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)

2 comments
Is filteringenabled on? and what type of script are you putting this in?
Filtering is not enabled. And I had it in a normal script. I tried putting it in a LocalScript, and I worked thanks for the help :)