Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to prevent the Player humanoid to die from a part

I made a pistol that fires a part and if a humanoid touches the part then he takes damage but I don’t want the player to die when he touches that part, I already tried using the ~= operator but it didn’t work. here is the code

local db = false

game:GetService("ReplicatedStorage").RemoteEvent.OnServerEvent:Connect(function(Player, Hit)
    local Shot = Instance.new("Part")
    Shot.BrickColor = BrickColor.new("New Yeller")
    Shot.CanCollide = false
    local BackPack = Player.Character
    Shot.Position = BackPack.Tool.Part.Position
    Shot.Shape = Enum.PartType.Block
    Shot.Size = Vector3.new(0.34, 0.228, 2)
    local VectorForce = Instance.new("VectorForce")
    local Attach = Instance.new("Attachment", Shot)
    VectorForce.Attachment0 = Attach
    VectorForce.RelativeTo = Enum.ActuatorRelativeTo.World
    VectorForce.Force = CFrame.lookAt(BackPack.Tool.Part.Position, Hit.Position).LookVector * 500
    VectorForce.Parent = Shot
    if not db then
        db = true
        Shot.Touched:Connect(function(hsit)
            if hsit:FindFirstChild("Humanoid") ~= Player.Character.Humanoid then
                hsit.Parent.Humanoid.Health = hsit.Parent.Humanoid.Health-5
                task.wait(2)
                db = false
            end
        end)
    end
    Shot.Parent = workspace
    game.Debris:AddItem(Shot, 3)
    task.wait(2)
    db = false
end)

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

"if hsit:FindFirstChild("Humanoid") ~= Player.Character.Humanoid then"

change this to "if hsit.Parent and hsit.Parent:FindFirstChild(‘Humanoid’) ~= Player.Character.Humanoid then"

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading