TeleportService Error

Hey everyone,

I have been developing a game recently and have been working on its lobby. There is a singleplayer mode and a multiplayer mode. However, the main game has a server size of four players, and I don’t want to make another place just for singleplayer.

I have been trying to figure out how to teleport one player to a private server once they click a mouse button, and here is the script I have:

Server:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TeleportService = game:GetService("TeleportService")

local Event = ReplicatedStorage.Singleplayer
local id = 12385310345

Event.OnServerEvent:Connect(function(plr)
	local Player = game.Players:FindFirstChild(plr)
	TeleportService:TeleportAsync(Player, id)
end)

And here is the local script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Event = ReplicatedStorage.Singleplayer

local Player = game.Players.LocalPlayer

script.Parent.MouseButton1Click:Connect(function()
	Event:FireServer(Player)
end)

Thank you in advance to anyone who helps :smiley:

That is not how you set the parameters.


Should be:

Event.OnServerEvent:Connect(function(plr)
	TeleportService:TeleportAsync(id, {plr})
end)
2 Likes

Also the Player argument isn’t required here, Roblox automatically passes the Player for you.

2 Likes

Thank you for your help, I will try this out soon.

--// Client Script //--
local TeleportService = game:GetService("TeleportService")

script.Parent.MouseButton1Click:Connect(function()
	TeleportService:TeleportAsync(id, {game.Players.LocalPlayer})
end)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.