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

Help with .Touched?

Asked by
FiredDusk 1466 Moderation Voter
8 years ago

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)
0
Is there an error? PreciseLogic 271 — 8y
0
Nope FiredDusk 1466 — 8y

1 answer

Log in to vote
1
Answered by
Pyrondon 2089 Game Jam Winner Moderation Voter Community Moderator
8 years ago

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.

Ad

Answer this question