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

Simple teleport-to-different-game script only working on studio mode?

Ok, so I posted a script similar to this before, but I revised it and it works on studio mode and studio mode only. I want it to teleport me to a game I made. Since the game is active, it will teleport me, but only in studio mode! I don't know what to do to fix it. whenever I click the button, the game lags and nothing happens. I turned it into a local script to see if i just needed to address the local player. here is my code:

local Part = workspace.Classic.Clickable
local CD = Part.ClickDetector
local GameId = 1233428613
local plr = game.Players.LocalPlayer

CD.MouseClick:connect(function()
	game:GetService('TeleportService'):Teleport(GameId, plr)
end) 

it seems so simple. What's the answer?

1 answer

Yes, your problem is how you are getting the player. In a normal script (Also a Server Script), you cannot use game.Players.LocalPlayer because the server doesn't know which player you want (The server sees all Players).

The good thing is that the ClickDetector and MouseClick() function you are using does have a parameter that gets the Player object that clicks on the ClickDetector. Simply put the parameter inside the () like so:

--in a Script:

local Part = workspace.Classic.Clickable
local CD = Part.ClickDetector

local GameId = 1233428613

CD.MouseClick:connect(function(playerThatClicked)
    game:GetService('TeleportService'):Teleport(GameId, playerThatClicked)
end) 

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