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

How to I teleport a player to a game?

Asked by 10 years ago

I am trying to Teleport a player using a ImgButton. But I don't see what is wrong with my script.

local Button = script.Parent
local teleportService = game:GetService("TeleportService")

function onClick()
    local Player = game.Players:GetPlayerFromCharacter(Click().Parent)
    if Player ~= nil then
        teleportService:Teleport(168955334,player)
    end

end
Button.MouseButton1Click:connect(onClick)

1 answer

Log in to vote
0
Answered by 10 years ago

Is this a LocalScript? If not, you should probably be using a LocalScript since you're dealing with Guis anyways.

If you are using a LocalScript, you can do this:

local Button = script.Parent
local teleportService = game:GetService("TeleportService")

function onClick()
    teleportService:Teleport(168955334)--Since you're using a LocalScript, you do not need the player
end

Button.MouseButton1Click:connect(onClick)
0
Thanks! GianniKun 40 — 10y
Ad

Answer this question