#TeleportService

1 messages · Page 1 of 1 (latest)

ocean widget
#

I am strugling with how can i make a Gui button teleport the player to another completly diferent roblox private place

elder trout
#

i believe you need to use TeleportService, and a LocalScript to get the player trying to teleport

ocean widget
#

like, i think i need to somehow get service mouse click am i right?

#

and then i dont have any ideia to how can i make the teleport

elder trout
#

no need for userinputservice when u have a button, you can just wire the mouse1 click event that the button has built-in to your own function

#

you'd get the service with a local ts = game:GetService("TeleportService")

full driftBOT
#

studio** You are now Level 1! **studio

elder trout
#

and then also get the player with the same method, getservice players

ocean widget
#

i can add the event on the button ?

#

and a local script

#

then event teleport in the server script storage?

elder trout
#

just a localscript in the button

#

then you get the services in that local script

ocean widget
#

so

#

i added the local script

#

and the remote event

elder trout
#

you can say script.Parent for the button 😛

#

and no need for the event, the event we will use is pre-coded in the button

#

so youd say local SPB = script.Parent

#

the script will refer to the script itself, and this way we would path to the script's parent (which is the button)

ocean widget
#

isnt working

elder trout
#

hmm

#

youll have to refer to the player thats pressing the button first, and then put all of this under a function

#

so youd do local player (or anything u want) = Players.LocalPlayer

ocean widget
#

no need for 2 line?

elder trout
#

i mean you can use it

ocean widget
elder trout
#

hmm so nice so far, the roblox creator hub tells us to use the new :TeleportAsync() instead of that

full driftBOT
#

studio** You are now Level 2! **studio

elder trout
#

in that function, the first thing is the placeId

#

second is p (the player that will press the button)

#

and third is the private server code

#

just the server code

ocean widget
#

lemme try

full driftBOT
#

studio** You are now Level 4! **studio

ocean widget
#

isnt working

#

😦

elder trout
#

so now we have the line of code thatll work when we click right

#

we need to make the button clicking call this code

ocean widget
#

oooh

#

so is like

#

game:GetService("MouseService")

elder trout
#

something similar, but you dont need to get a service for it

#

it comes with the button

#

so its SPB right

#

youd say SPB.MouseButton1Click

#

and this will make the script listen for someone pressing the button with a left click

#

once it detects u click the button, it will activate the line

#

and we can make it activate the server joining code we just wrote

ocean widget
#

i was trying something dumb

elder trout
#

so to translate this, once the button is clicked with mouse1, it connects to the function

ocean widget
#

maybe this?

elder trout
#

hmmm

#

so in my playtesting it says that the teleportservice can only be called by the server

#

and since this is a local script, meaning it runs on the client, it cant call it

#

lemme try something rq

ocean widget
elder trout
#

so i came up with a solution that i think will work

#

heres the full setup that i came up with

#

we have a script in sss, so that the server handles the teleporting process (since its a roblox requirement apparently)

full driftBOT
#

studio** You are now Level 3! **studio

elder trout
#

the first one is the teleporterscript

#

second is the script inside the button

#

if theres anything stuck on ur mind i can explain

ocean widget
#

i will try here

#

what the replicated storage means?

elder trout
#

its a place where things that are inside of it are replicated to both the server and the client

#

so if u have a script working on the client only, you can access it

#

which is how we were able to use the event in both a local script and a normal script

ocean widget
#

and the FireClient?

#

and teleprot async?

elder trout
#

fireclient makes it so that the event we made fires to a client, and in the brackets we put in any data we wanna transmit

#

teleportasync is like the fancy new version of the teleport command

elder trout
#

hmmm so with an event u have 2 variants

#

one is bindable which is server to server, and client to client communication

#

the one we use is a remote event, which allows for server - client communication

#

when we call this in our local script (which is the client), the data that we put inside the event is there now

#

later, in the teleporter script in serverscriptservice (which is the server), we can access it by saying onserverevent and get the data that was in that event

#

im not too good with words so ill try to illustrate it

#

if there are still questions on ur mind, there's a channel on youtube called "BrawlDev" that explains stuff like these in an interactive way

#

i can't focus on anything that doesnt have 4 screens of subway surfers gameplay on it, and i learnt this from him

ocean widget
#

thankyou so much bro

ocean widget
#

1- local

#

2- script

ocean widget
#

is the Fire Client

#

in the local script

#

maybe it needs to be on the SSS

#

?

#

@elder trout

frail furnace
ocean widget
#

dont works in the local script

frail furnace
#

well yeah 😭

ocean widget
frail furnace
#

what are u tryna do get someone to tp to a game?

full driftBOT
#

studio** You are now Level 5! **studio

ocean widget
#

like

#

single player, and multi player

#

each ones teleport to a diferent server

frail furnace
#

a lobby system?

ocean widget
#

and i need this teleport

ocean widget
frail furnace
ocean widget
#

its more like a text button that teleport

frail furnace
#

oh so its not a part but a button 😭

ocean widget
#

gui

frail furnace
#

a button u press that tps you to the game, with the option of playing single player and multiplayer?

ocean widget
#

i can send you the lobby

#

here is it

frail furnace
#

Lol i cant do nth with that without perms but i dont need it

#

what i do need

#

is the script that controls the tp

ocean widget
#

just to see the menu

ocean widget
frail furnace
#

wtv handles the behavior

ocean widget
#

local SPB = script.Parent
local SPBEVENT = game:GetService("ReplicatedStorage").TeleporterEven
local p = game:GetService("Players").LocalPlayer

SPB.MouseButton1Click:Connect(function(p)
SPBEVENT:FireClient(p)
end)

local tp = game:GetService("TeleportService")
local placeId = 14390772826
local code = tp:ReserveServer(placeId)
local SPBEVENT = game:GetService("ReplicatedStorage").TeleporterEvent

SPBEVENT.OnServerEvent:Connect(function(p)
tp:TeleportAsync(placeId, p, code)
end)

1- local
2-script

frail furnace
#

and u DO have a sss script to handle that right

frail furnace
#

sned that over too

ocean widget
#

sss script is number too

frail furnace
#

oh wait

#

ooh

#

alright also send a ss of the hierachy

#

for the button that tps player

#

so ik what its parented to

ocean widget
#

alr just a min

frail furnace
#

aigh

ocean widget
frail furnace
#

alr thanks

#

so errors in local script
1 using FireClient in LocalScript
2 parameter in MouseButton1Click
3 typo in RemoteEvent name

#

errors in sss
1 incorrect TeleportAsync use
2 reserving Server too early
3 event name mismatch

#

lowkey its mad easy to fix

frail furnace
#

ah in the MouseButton1Click function u have function(p)

ocean widget
#

and fire client too

frail furnace
#

fire client should be server not client

#

local sciprt has the easiest fixes so

local SPB = script.Parent
local SPBEVENT = game:GetService("ReplicatedStorage").TeleporterEvent
local p = game:GetService("Players").LocalPlayer

SPB.MouseButton1Click:Connect(function()
SPBEVENT:FireServer()
end)

elder trout
#

Oops might need to change that to fireserver

ocean widget
#

name dont mismatch more

#

local tp = game:GetService("TeleportService")
local placeId = 14390772826
local code = tp:ReserveServer(placeId)
local SSSSPBEVENT = game:GetService("ReplicatedStorage").TeleporterEvent

SSSSPBEVENT.OnServerEvent:Connect(function(p)
tp:TeleportAsync(placeId, p, code)
end)

ocean widget