Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do i make it so when a player isnt wearing a suit they will slowly take damage?

Asked by 2 years ago

This is my script but it isnt working and yes there is "HasSuit" Value inside the Humanoid

script.Parent.Touched:Connect(function(plr)
    if not plr.Humanoid:FindFirstChild("HasSuit") then
        repeat
            plr.Humanoid.Health = plr.Humanoid.Health - 3
        until not plr:FindFirstChild("Humanoid")
    end
end)

1 answer

Log in to vote
0
Answered by 2 years ago
Edited 2 years ago

1.A touched event gives you the part that touched it (example: "Left Leg", "Right Leg") meaning it wont always be a descendant of a player's character, it could be a random part touching it

Your Code should look something like this:

script.Parent.Touched:Connect(function(part)

            if game.Players:GetPlayerFromCharacter(part:FindFirstAncestorOfClass("Model")) then
                local player = game.Players:GetPlayerFromCharacter(part:FindFirstAncestorOfClass("Model"))
                local char = player.Character


                if  char:FindFirstChild("Humanoid") then
                        if not char.Humanoid:FindFirstChild("HasSuit") then

                        repeat

                            if char.Humanoid.Health - 3 > 0 then
                                char.Humanoid.Health -= 3
                            else
                                char.Humanoid.Health = 0
                            end
                            wait(0.1)--can change to increase or decrease how long it takes to kill the player

                        until char.Humanoid.Health <= 0


                end
                end



            end

        end)
Ad

Answer this question