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

Why isn't Touched working?

Asked by 9 years ago

This script is supposed to Disable a script when you touch it, and enable it when you stop touching it, but it won't fire.

script.Parent.Touched:connect(function(part)
    local h = part.Parent:FindFirstChild("Humanoid")
    print 'touched'
    if h then
        game.Players.LocalPlayer.PlayerGui.MouseScripts.MouseS.Disabled = true
        script.Parent.TouchEnded:connect(function()
            game.Players.LocalPlayer.PlayerGui.MouseScripts.MouseS.Disabled = false
        end)
    end
end)

No errors or anything.

1 answer

Log in to vote
0
Answered by
SurVur 86
9 years ago

Well, if this is a localscript, then the problem is that localscripts don't fire in workspace. I would assume that the script's Parent is a part and therefore the script is a descendant of workspace. We could use game.Players:GetPlayerFromCharacter() to find the player and then edit the script within the player.

script.Parent.Touched:connect(function(part)
    local h = part.Parent:FindFirstChild("Humanoid")
    print 'touched'
    if h then
        local player = game.Players:GetPlayerFromCharacter(part.Parent)
    player.PlayerGui.MouseScripts.MouseS.Disabled = true
        script.Parent.TouchEnded:connect(function()
           player.PlayerGui.MouseScripts.MouseS.Disabled = false
        end)
    end
end)

Ad

Answer this question