I have created a Script that teleports a Player to the Position (0, 0, 0). I would like the player to have to click it with a ClickDetector. How do I change the Script?
function onTouched(hit) local human = hit.Parent:findFirstChild("Humanoid") if (human ~= nil ) then print("Human touched teleport") hit.Parent.Torso.CFrame = CFrame.new(0, 0, 0) end end script.Parent.Touched:connect(onTouched)
Place this script in the part you want to be clicked for the function to operate.
SCRIPT
local part = script.Parent -- get the part local clickDetector = Instance.new("ClickDetector", part) -- add a clickdetector to the part clickDetector.MouseClick:connect(function(player) --connect and call the function local human = player.Character:findFirstChild("Humanoid") if human then -- if no humanoid then it wont continue print("Teleport was Clicked!") -- print whatever to see if it works player.Character.Torso.CFrame = CFrame.new(0, 0, 0) -- parent of 'human' should hte the character, this will set the cframe of the torso to the position 0,0,0 else print("Didn't work!") end end)
The player is already an argument with the MouseClick event, so in the function, in the parameters you add the argument of the player, in this example it's going to be named 'player'