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

Why doesn't my game teleport the player when he clicks a button?

Asked by 3 years ago

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:

local tp = game:GetService("TeleportService")
local m = require(game.ReplicatedStorage.PlaceIDs)

script.Parent.MouseButton1Click:Connect(function()
    tp:Teleport(m.tp1, game.Players.LocalPlayer)
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.

0
There doesn't seem to be an issue with the script itself(you can remove the LocalPlayer argument though, since running this function from the client doesn't need the player parameter). Dannys72344 44 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

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:

local TeleportService = game:GetService("TeleportService") --gets teleport service
local Module = require(game.ReplicatedStorage.PlaceIDs) --requires the placeids module
local Player = game.Players.LocalPlayer --gets the localplayer as a player variable

script.Parent.MouseButton1Click:Connect(function() --event for when your gui is clicked
   local TP1 = Module.TP1 --reference variable for TP1
   TeleportService:Teleport(TP1, Player) --teleports the player, passing the placeid, and the localplayer variable.
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!

0
It works! Thank you! Have a good day too. SussiestBalss 40 — 3y
0
No problem man! gamernight687 138 — 3y
Ad

Answer this question