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

Why does this script not kill the player?

Hey, I did not ask a question for a longer time. (I guess thats good tho)

Problem

I am trying to make a script that kills a player after some time if they do not touch a part.

Script

for i, user in ipairs(game.Players:GetChildren()) do
	local char = user.Character
	local part = workspace.InZone
	local h = part.Parent:FindFirstChild("Humanoid")
	if h~= nil then
		h.Health = h.Health -200
	end
end

3 answers

I seriously don't see why you bother with this workspace.InZone thing. Also is this a script or localscript? (It should be a script)

for i, user in ipairs(game.Players:GetChildren()) do local char = user.Character char:FindFirstChild("Humanoid") if h~= nil then h.Health = h.Health -200 end end

In order to do this, you must make a loop to count time and a checker for when the part has been touched. There are 2 functions that do this, :GetTouchingParts() Or the event, Touched. Here are wiki articles for them: Touched GetTouchingParts

If you have anymore questions reply to this answer.

Try This:

for i, user in ipairs(game.Players:GetChildren()) do
	local char = user.Character
	local humanoid = char.Humanoid
	humanoid.Health = humanoid.Health - 100
end

Make sure it is a Script not a LocalScript.

Hope this helps!

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