Hello, I made this script that is supposed to teleport the player to spawn when the player clicks on a button. I set it up in StarterGui, then I created a billboardgui, and then a text button. it works when I click on the play in the Roblox editor, but when I publish it to Roblox, it does not work.
countdown = 7 local i = 1 spawn2 = game.Workspace.SpawnLocation time2 = 7 player = script.Parent.Parent.Parent.Parent player2 = game.Players.LocalPlayer.Name function onClicked() if script.Parent.Text == ("Teleport to Spawn") then for i = countdown,1, -1 do script.Parent.Text = (i) wait(1) end script.Parent.Text = ("Teleport to Spawn") player.Character:MoveTo(spawn2.Position) local h = game.Workspace:findFirstChild(player2):findFirstChild("ForceField") if h~=nil then h:remove() end end end script.Parent.MouseButton1Down:connect(onClicked)
A simpler way to do just that (and this one works):
gui = script.Parent player = game.Players:GetPlayerFromCharacter(gui) function onClick() if player ~= nil then local Destination = game.Workspace.Destination player.Torso.CFrame = CFrame.new(Vector3.new(Destination.Position.x, Destination.Position.y + 2, Destination.Position.z)) wait(1) end gui.MouseButton1Down:connect(onClick)
Try that and see how it works.