I have a script so when a player clicks a button, he gets teleported to another game. Whenever I test it, I get nothing. No error, nothing in the output. I tried to run the game in roblox itself but still nothing. My code:
1 | local tp = game:GetService( "TeleportService" ) |
2 | local m = require(game.ReplicatedStorage.PlaceIDs) |
3 |
4 | script.Parent.MouseButton 1 Click:Connect( function () |
5 | tp:Teleport(m.tp 1 , game.Players.LocalPlayer) |
6 | end ) |
Whenver I print the "m.tp1" it gives me the id of the game, so I don't know what I am doing wrong.
Hmm, I don't see what you're doing wrong. I'm pretty sure you would just set the localplayer and the placeid as an individual variable, because for some reason, sometimes I have to make a variable, for the script to work. Try using this script:
1 | local TeleportService = game:GetService( "TeleportService" ) --gets teleport service |
2 | local Module = require(game.ReplicatedStorage.PlaceIDs) --requires the placeids module |
3 | local Player = game.Players.LocalPlayer --gets the localplayer as a player variable |
4 |
5 | script.Parent.MouseButton 1 Click:Connect( function () --event for when your gui is clicked |
6 | local TP 1 = Module.TP 1 --reference variable for TP1 |
7 | TeleportService:Teleport(TP 1 , Player) --teleports the player, passing the placeid, and the localplayer variable. |
8 | end ) |
Also, note that you can't use teleportservice in studio, so make sure you test it out in the game.
Hopefully, the variables should make it work. I hope I helped you, and have an awesome day!