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

How do I set up a teleport GUI?

Asked by
PKRoss 5
8 years ago

Hello,

I'm trying to create a GUI that teleports the player who clicks it to another game.

I've set it up like this: StarterGui>ScreenGUI>ImageButton>Script

I'm certain the issue is not how the GUI is structured but I included it just to be safe. Anyways, this is my script:

function onClicked(click)

    local player = game.Players:GetPlayerFromCharacter(click.Parent)
    if player then
        game:GetService("TeleportService"):Teleport(299324552, player)
    end
end


script.Parent.MouseButton1Down:connect(onClicked)

What am I doing wrong here? I can click it just fine, but nothing happens.

This is what Output says: 18:34:45.296 - Script 'Players.Player.PlayerGui.ScreenGui.ImageButton.Script', Line 3

What's the issue here? Thank you in advanced.

2 answers

Log in to vote
0
Answered by
DevArk 50
8 years ago

I would put this in a localscript and make it like so:

local plr = game.Players.LocalPlayer
repeat wait() until plr.Character -- so that no errors occur later on with nill children

script.Parent.MouseButton1Down:connect(function()
    game:GetService('TeleportService'):Teleport(299324552)
end)
0
Works, thanks! PKRoss 5 — 8y
Ad
Log in to vote
0
Answered by 8 years ago

If I'm correct, when saying ":GetPlayerFromCharacter(click.Parent)" you're not actually getting the player. Try this instead of line 3:

local player = script.Parent.Parent.Parent.Parent

Answer this question