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

Why isn't Touched working?

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

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)

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