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

Invalid Player To Teleport. Why?

Here is more details.


game.ReplicatedStorage.Server1.OnServerEvent:Connect(function()
	local player = game:GetService("Players").LocalPlayer
	game:GetService("TeleportService"):Teleport(4931146666,player)
end)

this is a script normal script inside serverscriptservice. When server 1 is fired from a localscript then it should teleport the player to another place. Why do i get invalid player to teleport if local player = game.Players.LocalPlayer that is good why do i get this problem

2 answers

The Server cannot reference a local Player Object, as it isn't a Client machine, it's the Server. Fortunately, you can link the Player Object that initiated the RemoteEvent through the PlayerFired parameter.

game.ReplicatedStorage.Server1.OnServerEvent:Connect(function(Player)
    game:GetService("TeleportService"):Teleport(4931146666,Player)
end)

game.Players.LocalPlayer is using only in LocalScript, so put your code into LocalScript i think

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