Player spawns at pending spawn instead of their team spawn

So I’ve created a GUI that allows you to select your team. After you’ve selected your team, it assigns you to your selected team and respawns you. However, instead of you spawning at your new team’s spawn, you spawn at the pending spawn. I’ve tried fixing it a couple of times by myself, but it still doesn’t spawn you at your team’s spawn. This is my script

local player = game.Players.LocalPlayer
local team = game.Teams["Example Team"]
local spawnplace = game.Workspace.TeamSpawns.ExampleTeamSpawn

script.Parent.MouseButton1Click:Connect(function()
	player.Team = team
	script.Parent.Parent.Parent.Visible = false
	player.Character.Humanoid.Health = 0
	player.RespawnLocation = spawnplace
end)

Also, sorry if I’m using devforum wrong in a way. This is my first time posting.

You must use a local script (cilent) for this

local player = game.Players.LocalPlayer
local team = game.Teams["Example Team"]
local spawnplace = game.Workspace.TeamSpawns.ExampleTeamSpawn.Position --This must be a part

script.Parent.MouseButton1Click:Connect(function()
	player.Team = team
	script.Parent.Parent.Parent.Visible = false
	player.Character.Humanoid.Health = 0
	player.RespawnLocation = spawnplace
end)

Thank you for responding! However, it sadly still won’t work. I’ve made sure the script was a LocalScript, and changed the spawnplace into part, but it won’t work. Thank you for trying to help

Oops, sorry about that but did you tried this out?
image

I don’t really know what does it works but you probably need to be on a team same colour as the TeamColor i said above. I think it would be helpful for you.

Yes. I’ve double-checked multiple times, and the teamcolors are the same on both the team and the spawn.

1 Like

Use a script to set the player’s team.
https://developer.roblox.com/en-us/api-reference/property/Player/Team

script.Parent.MouseButton1Click:Connect(function(player)
	-- fire a RemoteEvent here linked to a script to change the player's team
	script.Parent.Parent.Parent.Visible = false -- this must stay in this LocalScript
	player.Character.Humanoid.Health = 0 -- put this in the script linked by the RemoteEvent
	player.RespawnLocation = spawnplace -- put this in the script too
end)

I’m pretty sure a player’s team property does replicate from the server to the client (it obviously won’t replicate the other way but the documentation’s information is slightly outdated).

https://developer.roblox.com/en-us/api-reference/property/Player/TeamColor

Just ran a short test & it does, as expected.

--SERVER

game.Players.PlayerAdded:Connect(function(player)
	task.wait(10)
	player.Team = game.Teams.TEST2
end)
--LOCAL

while task.wait(1) do
	print(game.Players.LocalPlayer.Team)
end

image

image

wouldn’t work since “Neutral” is set to true