You need a remote event. Name it TeleportToSpawn and put it in replicatedStorage.
Code:
testGui.YourButton.MouseButton1Click:Connect(function()
game.ReplicatedStorage.TeleportToSpawn:FireServer()
testGui.YourButton:Destroy()
end)
game.ReplicatedStorage.TeleportToSpawn.OnServerEvent:Connect(function()
local char = player.Character
local humanRP = char.HumanoidRootPart
humanRP.Position = game.Workspace.Spawn.Position + Vector3.new(0,3,0)
end
If you don't understand the code, then I suggest to watch some videos on the humanoid (R6 and R15), remote functions, and the difference between client and server. I hope it helps you :)
1 comment
The way is correct, but another way, somewhat easier would be to set the players respawnlocation to lobbySpawn and use the LoadCharacter function.
player.RespawnLocation = lobbySpawn player:LoadCharacter()