Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 6 years ago

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

Log in to vote
0
Answered by
xPolarium 1388 Moderation Voter
6 years ago
Edited 6 years ago

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) 

Ad

Answer this question