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

Help with .Touched?

So what I am trying to do is kinda like in a tycoon door. So what I am wanting is where a person can claim a door when it is touched but if the name does not equal to the first name that has touched then it kills them. (Kinda like a tycoon door)

script.Parent.Touched:connect(function(hit)
	local hum = hit.Parent:FindFirstChild("Humanoid")
	if hum then
		local PlayersName = script.Parent:WaitForChild("PlayersName")
		PlayersName.Value = hit.Parent.Name
		if hit.Parent.Name ~= PlayersName.Value then
			hum.Health = hum.Health - 100
		end
	end
end)

2 comments

0

Is there an error?

0

Nope

1 answer

✓ Accepted answer

Assuming PlayersName is a value in the door, you need to check if it's taken before setting it.

script.Parent.Touched:connect(function(hit)
	local hum = hit.Parent:FindFirstChild("Humanoid")
	if hum then
		local PlayersName = script.Parent:WaitForChild("PlayersName")
		if PlayersName.Value == "" then -- "" being whatever the default value is.
			PlayersName.Value = hit.Parent.Name
		elseif hit.Parent.Name ~= PlayersName.Value then
			hum.Health = 0
		end
	end
end)

Hope this helped.

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