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.
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)
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