Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.