Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

why does this code not work? (GUI) game Teleporter gui but when you click...

i am following a game teleporter tutorial and the code does not work? the problem is when you click you don't teleport the error in line 8?

code:

local Plr = game.Players.LocalPlayer
local Tps = game:GetService("TeleportService")
local Rs = game.ReplicatedStorage


script.Parent.MouseButton1Click:Connect(function()
	Tps:SetTeleportGui(Rs:FindFirstChild("TeleportGui"))
	Tps:Teleport(166986752,Plr)
	
	
end)


4 comments

1

Because you can only teleport players in a serverscript. Use a remote event to :FireServer and teleport the player.

0

can i get a exemple?

0

pls

1 answer

Right. You need to use remote events since TeleportService can only be used on the server. Remote events communicate between the client-server. We do not need to pass any parameters except the player parameter, so we'll leave the FireServer() blank.

Note: Put a remote event in ReplicatedStorage.

local plr = game.Players.LocalPlayer
local rs = game.ReplicatedStorage

script.Parent.MouseButton1Click:Connect(function()
	rs.RemoteEvent:FireServer() --We do not need any parameters. It will pass on the player parameter.
end)

And now the server script. You can put it anywhere, but I suggest ServerScriptService.

local rs = game.ReplicatedStorage
local re rs.RemoteEvent
local tps = game:GetService("TeleportService")

re.OnServerEvent:Connect(function(player) --It passes the specific player parameter.
	tps:SetTeleportGui(rs:FindFirstChild("TeleportGui"))
	Tps:Teleport(166986752, plr)
end)

2 comments

0

how would i make it accessible to every one?

0

This IS acceptable to everyone.

This discussion is preserved as it was. New answers, comments, and votes are closed.