How can I set a character's spawn location in a given team?

Hey guys, hope everyone is having a nice day.

local Teams = game:GetService("Teams")
local Character = player.Character or player.CharacterAdded:Wait()

-- spawnpoints
local blueSpawn = game.Workspace.team1
local redSpawn = game.Workspace.team2


if Humanoid.Health == 0  then
	
	print(player.Name , " is dead..")
	onDeath:FireServer(player , Humanoid)
	task.wait(5)
	
	if player.Team == Teams.Blue then

		Character:MoveTo(blueSpawn.Position)
		print(player.Name.."Has returned to blue spawn point [worked]")
	end
end

i’m trying to make it so when a humanoid dies, or respawns. I want them to respawn at the blue location, but this isn’t working. Are there any other ways for this?

Let me know, Thanks.

If it’s a SpawnLocation instance and the player is associated with that team, there’s a property within the instance that allows you to associate that SpawnLocation with the given team (I think by setting TeamColor). This means the player will always respawn at that location with no scripting involved.

Otherwise, you can set a part above the location with collisions off. You could then try something like:

player.Character.Humanoid.Died:Connect(function()
    player.CharacterAdded:Once(function(char)
        char:WaitForChild("HumanoidRootPart").CFrame = spawnPartHere.CFrame
    end)
end)

Hey!

Thanks for the response, but this doesn’t seem to solve the issue.

Humanoid.Died:Connect(function(hmm)

Character:WaitForChild("HumanoidRootPart").CFrame = teamAspawn.CFrame

end)

I've tried adjusting your code but this still does not work.

You’re detecting the character that’s already died. Try what I showed above - if you haven’t already.

player.Character.Humanoid.Died:Connect(function()
    player.CharacterAdded:Once(function(char)
        char:WaitForChild("HumanoidRootPart").CFrame = teamAspawn.CFrame
    end)
end)

Or, if it is a SpawnLocation instance, change the TeamColor property of that to your team’s colour.