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

How to teleport to another place after you click a gui?

Asked by 2 years ago
Edited 2 years ago

My script:

local object = script.parent
local TeleportService = game:GetService("TeleportService")
local Players = game:GetService("Players")

local localplayer = Players.LocalPlayer

local function onActivated()


    TeleportService:Teleport(7890554078,localplayer)


end
object.Activated:Connect(onActivated)

it does nothing i dont no why this is only the part of the code relating to teleporting if there is nothing wrong with this i can send my entire script so that you can check if something else is affecting it

0
Are you trying to teleport in Studio? You can't teleport to another place in Studio but it should tell that in your output but if you wanted to test the actual teleportation out you would have to actually play the game with Roblox Player Henkkazor 5 — 2y

1 answer

Log in to vote
0
Answered by
Miniller 562 Moderation Voter
2 years ago
Edited 2 years ago

Okay so it seems like you are new to coding, let me recommend you this site. I assume that the object is the TextButton and I also assume that the Activated event actually triggers (you can confirm that by putting something like print("hi") in the function) Now, you should never ever teleport a player with a localscript. Use a RemoteEvent. I will be nice and give you the code you need this time So put a remoteevent in ReplicatedStorage and call it teleport. In the onActivated function you would fire that event by game.ReplicatedStorage.teleport:FireServer(). (In case you're wondering, you don't have to pass the localplayer variable in the function because it automatically does that for you.) Then, you need a Script. Put it in the serverscriptservice. In that script, you will need to listen for the event so you can teleport the player. This is a nice little way of handling events without creating extra functions for them:

game.ReplicatedStorage.teleport.OnServerEvent(function(player)
    --the actual teleporting part
    player.Character.HumanoidRootPart.CFrame = workspace.object.Position+CFrame.new(0,5,0)
end)

Now obviously you have to replace workspace.object.Position with the object/coordinates you want to teleport your player to/at.

0
ok thanks alot and yes i am new to coding rabidazara 6 — 2y
Ad

Answer this question