Spawning in the wrong locations

(dunno which category this goes in sorry)

Hey guys. So whenever I die in my game i almost always respawn at the wrong spawnpoint.

I’ve checked the spawn points and the teams and all of them match their TeamColor.
image
image
image

So why am I spawning at the wrong spawn locations?

1 Like

have you tried unchecking “neutral”

2 Likes

I unchecked neutral on all of them and now i just spawn over the void. And If I uncheck netraul on all but 1 i just always spawn at that 1 spawn point no mater what team im on.

It’s likely that your character spawns before assiging you a team.
Show me your team assign script

Here is my TeamPlayer script. This runs after the loading screen has finished loading in my game.

local rep = game.ReplicatedStorage

rep.Events.TeamPlayer.OnServerEvent:Connect(function(plr)
	
	
	if plr.JailSystem.isArrested.Value == true then
		plr.Team = game.Teams.Jailed
	
	elseif plr:GetRankInGroup(34363373)>= 253 then
		plr.Team = game.Teams["Chiefs of Staff"]
	
	elseif plr:GetRankInGroup(34737726) >= 8 then
		plr.Team = game.Teams["Royal Military Police"]

	elseif plr:GetRankInGroup(34363373) >= 16 then
		plr.Team = game.Teams["Headquarters"]
		
	elseif plr:GetRankInGroup(34363373) >= 15 then
		plr.Team = game.Teams["General Grade Officers"]
		
	elseif plr:GetRankInGroup(34363373) >= 11 then
		plr.Team = game.Teams["Field Grade Officers"]
		
	elseif plr:GetRankInGroup(34363373) >= 8 then
		plr.Team = game.Teams["Junior Officers"]
		
	elseif plr:IsInGroup(34737726) then
		plr.Team = game.Teams["Royal Military Police"]
		
	elseif plr:IsInGroup(34364980) then
		plr.Team = game.Teams["15th Infantry Division"]
		
	elseif plr:IsInGroup(34363373) then
		plr.Team = game.Teams["British Army Personnel"]
	end
end)

If thats what you were looking for. Lmk if thats not what you were looking for

i see you have a few groups;

consider using this function to speed up giving teams

local cache = {}
local function getPlayerRankInGroup(player:Player, group:number)
	if not cache[player] then
		cache[player] = {}
		player.AncestryChanged:Once(function()
			cache[player] = nil
		end)
	end
	
	if cache[player][group] then
		return cache[player][group]
	end
	
	cache[player][group] = player:GetRankInGroup(group)
	return cache[player][group]
end

so instead of doing plr:GetRankInGroup(34363373) you do
getPlayerRankInGroup(plr, 34363373)

And about your problem:
I have a question as to why you use a remote event here? Shouldn’t this be a one time thing when the player joins the game?

Using a remote event cuz my loading screen is handled in a localscript so I am firing the remoteevent after the loading screen is done loading.

But I also have a seperate script that literally manually places the player at their correct spawn after joining which works fine but when they reset ingame they spawn at the wrong locations.

send me that script ill patch it up for ya

Nah i dont want that cuz I was working on it all day yesterday to make sure jailed people spawn in the jail.

But sure here it is:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Events = ReplicatedStorage.Events
local SpawnPoints = workspace:WaitForChild("SpawnPoints")



-- Define the server event handler for spawning players
Events.SpawnPlayer.OnServerEvent:Connect(function(player)
	local character = player.Character
	
	local isArrested = player:WaitForChild("JailSystem").isArrested
	local TimeLeft = player:WaitForChild("JailSystem").TimeLeft
	
	-- Wait for the player's character to load
	if not character or not character.Parent then
		character = player.CharacterAdded:Wait()
	end

	-- Check the player's group rank
	local groupId = 34363373  -- Replace with your group ID
	local rank = player:GetRankInGroup(groupId)

	-- Define spawn points based on rank conditions
	if player.JailSystem.isArrested.Value == true then
		character:MoveTo(SpawnPoints.JailSpawn.Position)
		player.PlayerGui:WaitForChild("TimeLeftArrested").Frame.Visible = true
		for remainingTime = TimeLeft.Value,0 , -1 do
			player.PlayerGui.TimeLeftArrested.Frame.TimeLeft.Text = "Time Left: "..remainingTime
			wait(1)
		end
		
		isArrested.Value = false
		TimeLeft.Value = 0
		player:LoadCharacter()
		
	elseif rank >= 200 then
		character:MoveTo(SpawnPoints.Headquarters.Position)
	elseif rank >= 14 then
		character:MoveTo(SpawnPoints.Headquarters.Position)
	elseif rank >= 8 then
		character:MoveTo(SpawnPoints.Officers.Position)
	elseif player:IsInGroup(34364980) then  -- Example of checking another group
		character:MoveTo(SpawnPoints.Infantry15.Position)
	elseif player:IsInGroup(0000) then  -- Replace with the group ID
		character:MoveTo(SpawnPoints.Armored6.Position)
	else
		-- Default spawn point or handling for players not in specified groups
		character:MoveTo(SpawnPoints.Civilians.Position)
	end
end)

and another place you can benefit from using the function i wrote earlier; actually best case is you put that function in a module.

Then uh, dont really know what you want anymore.

My spawn issue was never fixed. Like not on spawning, that works perfectly but after a player dies or resets. They spawn at the wrong spawnpoint, is it possible to make a script that like manually places them at their spawn point.

I tried doing this but it didnt seem to work.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Events = ReplicatedStorage.Events
local SpawnPoints = workspace:WaitForChild("SpawnPoints")


game.Players.PlayerAdded:Connect(function(plr)
	local character = plr.Character
	
	character.Humanoid.Died:Connect(function()
	wait(plr.CharacterAppearanceLoaded)
		
		if plr.Team == game.Teams["15th Infantry Division"] then
			plr.Character:MoveTo(SpawnPoints.Infantry15.Position)
			
		elseif plr.Team == game.Teams["British Army Personnel"] then
			plr.Character:MoveTo(SpawnPoints.Infantry15.Position)
		
		elseif plr.Team == game.Teams["Chiefs of Staff"] then
			plr.Character:MoveTo(SpawnPoints.Headquarters.Position)
			
		elseif plr.Team == game.Teams["Civilians"] then
			plr.Character:MoveTo(SpawnPoints.Civilians.Position)
			
		elseif plr.Team == game.Teams["Field Grade Officers"] then
			plr.Character:MoveTo(SpawnPoints.Officers.Position)
			
		elseif plr.Team == game.Teams["General Grade Officers"] then
			plr.Character:MoveTo(SpawnPoints.Headquarters.Position)
			
		elseif plr.Team == game.Teams["Headquarters"] then
			plr.Character:MoveTo(SpawnPoints.Headquarters.Position)
			
		elseif plr.Team == game.Teams["Jailed"] then
			plr.Character:MoveTo(SpawnPoints.JailSpawn.Position)
			
		elseif plr.Team == game.Teams["Junior Officers"] then
			plr.Character:MoveTo(SpawnPoints.Officers.Position)
			
		elseif plr.Team == game.Teams["Royal Military Police"] then
			plr.Character:MoveTo(SpawnPoints.RMPSpawn.Position)
		end
	end)
end)```

instead of this

do

plr.CharacterAdded:Connect(function()
-- code here
end)

i suppose you only want this to run on your second character spawn;
do this instead

if not plr.Character then plr.CharacterAdded:Wait() end
plr.CharacterAdded:Connect(function()
-- code here
end)

This seems to work perfectly. Thank you!