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