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

More help with the touched event. [?]

Asked by 9 years ago

I'm making a script that if you touch a block it adds a sting value, "Safe". The problem was if there were two of these blocks inside each other and you stopped touching one while touching the other, he value still gets removed. I fixed that error and now my script doesn't work, help?

function On(hit)
if hit.Parent:FindFirstChild("Torso") then
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player:FindFirstChild("Safe") == nil then
    local value = Instance.new("StringValue",player)
    value.Name = "Safe"
end
end
end
function Off(hit)
if hit.Parent:FindFirstChild("Torso") then 
    if hit.Parent:FindFirstChild("Torso").Touched == false then --error is here
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
    local value = player:FindFirstChild("Safe")
    value:remove()
end
end
end
script.Parent.Touched:connect(On)
script.Parent.TouchEnded:connect(Off)

Answer this question