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

Why is this teleport script working in Studio, but not online in the game?

So I made a teleport script using Players instead of using game.Workspace.Player:MoveTo...

function onTouch(plr)
game.Players.Player.Character:MoveTo(Vector3.new(21, 66.9, -96.5))
end
game.Workspace.Teleporter.Touched:connect(onTouch)

and it works, but it doesn't work online? Why , and what am I doing wrong? I thought that if I used Players instead of using Workspace.Players it would work..

2 answers

✓ Accepted answer

Your script assumes that the player's name is Player, you have to change that. In your code, the argument plr is the part that touched the teleport, which will most likely belong to some player's character. I've changed it to hit, as that makes more sense.

function onTouch(hit)
	if hit.Parent then
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
		if player then
			player.Character:MoveTo(Vector3.new(21, 66.9, -96.5))
		end
	end
end
game.Workspace.Teleporter.Touched:connect(onTouch)

I believe the issue was in line 2, the way you where getting the player. you did not specify what Player was. The script automatically assumes the players name is Player Code

function onTouch(plr)
plr.Parent:MoveTo(Vector3.new(21, 66.9, -96.5))
end
game.Workspace.Teleporter.Touched:connect(onTouch)

Hope this helps!

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