So, I've done it before with a part touch, now I'm trying to make a GUI button teleport you to a different game, I tryed changing the part touch script teleport to work for a GUI button click instead, so I made this but it didn't work:
function onTouched(click) local player = game.Players:GetPlayerFromCharacter(click.Parent) if player then game:GetService("TeleportService"):Teleport(228755269, player) end end script.Parent.MouseButton1Click:connect(onTouched)
Help me?...
Just make it a local script. Since with local scripts you can get the player easily. Also, MouseButton1Down does not return player sadly. Because if you're using a server script you can just do script.Parent.Parent.Parent.Parent
and you get the player... Because with a local script the TeleportService already knows who to teleport(You), you don't need the whole player thing.
(Local Script)
script.Parent.MouseButton1Click:connect(function() game:GetService("TeleportService"):Teleport(228755269) end)
I turned your 8 lined script into 3 lines.
Hope this helps!
s = game:service("TeleportService") id = 00000000 function onClicked() s:Teleport(id) end script.Parent.MouseButton1Click:connect(onClicked)
-- Make sure you make this a Local Script but still put this in a textbutton guied. And change the 0000000 to the game you want to be teleported to.