Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Teleport to spawn button only working in the Roblox editor. But not when published to Roblox?

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

0

Is filteringenabled on? and what type of script are you putting this in?

0

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 :)

1 answer

✓ Accepted answer

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.

1 comment

0

Does not work. Also does not work in the Roblox Editor. But I found the problem, it was that I had it in a normal script, but I needed it in a LocalScript.

This discussion is preserved as it was. New answers, comments, and votes are closed.