I'm trying to make a script that teleports someone who clicks a button, but it never works in game it only works in studio. What did I do wrong?
function onClicked(playerWhoClicked) hum = game.Players.LocalPlayer.Character hum.Torso.CFrame = CFrame.new(script.Parent.Parent.Teleport.Position) end script.Parent.ClickDetector.MouseClick:connect(onClicked)
[Edited] You should use the player value that is in the function.. Here is your script using it. Also, I edited some stuff that is unnecessary.
script.Parent.ClickDetector.MouseClick:connect(function(plr) --Plr is a short way to say player. It makes writing your scripts easier. game.Workspace[plr.Name].Torso.CFrame = CFrame.new(script.Parent.Parent.Teleport.Position) --I am just saying, but you should use the head to make it R15 compatible. end)
Put this inside of the button script
local spawn = game.Workspace.TeleportLocation -- make a brick in the Workspace name 'TeleportLocation'. player = script.Parent.Parent.Parent.Parent.Parent.Parent -- if this script doesn't work, look at this line. Make sure the final Parent is Workspace. function onClicked() player.Character.Torso.CFrame = CFrame.new(spawn.Position) end script.Parent.MouseButton1Down:connect(onClicked)
Accept answer and up vote if this works, thank!