local ting = 0 function onTouch(hit) if ting == 0 then ting = 1 local check = hit.Parent:FindFirstChild("Humanoid") if check ~= nil then local user = game.Players:GetPlayerFromCharacter(hit.Parent) print("player got found") end end ting = 0 end script.Parent.Touched:connect(onTouch)
I just would like to know how to change it to a Clicked script but still work.
It's actually a whole lot easier than Touched. First off, you need to insert a ClickDetector into the Part, along with the script. We will use the MouseClick
event of the ClickDetector to detect when someone clicks.
The part of this that makes it so much easier is the built in parameters. Touched's built in parameter is the part that fired the event, so it might be equal to your left leg or something. But because anything can fire the event, you have to make sure the Humanoid exists, like you did on line 7. You then have you use GetPlayerFromCharacter to be able to use the player.
This isn't necessary for the MouseClick event. Its built in parameter is equal to the Player who clicked. This makes all those checks we did for Touched not needed. Check it out;
function onClick(player) print(player.Name.." was found!") end script.Parent.ClickDetector.MouseClick:connect(onClick)