Help with custom character being applied to the player

Hello. I’m currently making a system in which, depending on join order, the player is assigned a number the corresponds with a custom character. Here I’m using a script under ServerScriptService that assigns a number value to a player depending on the amount of players already in the game, and switching them to that specific character. In my game, I only want one of each character to exist at a time, and so far, only the value registering works. The player does not change to the desired character. How would I go about fixing this? Here is my code:

-- Get services
local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")

-- Function to get the number of players in the game and change the character
Players.PlayerAdded:Connect(function(player)
	print(#Players:GetChildren())
	
	if #Players:GetChildren() == 1 and #Players:GetChildren() ~= 2 then
		
		local value = Instance.new("NumberValue")
		value.Name = "Character#"
		value.Value = #Players:GetChildren()
		value.Parent = player
		if value == 1 then
			
			local character1 = ServerStorage.Characters:FindFirstChild("OfficerShaw")
			local character1Clone = character1:Clone()
			local playerCharacter = player.Character
			character1.Name = player.Name
			playerCharacter = character1Clone
			character1Clone.Parent = game.Workspace
		end
		
	elseif #Players:GetChildren() == 2 and #Players:GetChildren() ~= 1 then
		
		local value = Instance.new("NumberValue")
		value.Name = "Character#"
		value.Value = #Players:GetChildren()
		value.Parent = player
		if value == 2 then
			
			local character2 = ServerStorage.Characters:FindFirstChild("OfficerAdrius")
			local character2Clone = character2:Clone()
			local playerCharacter = player.Character
			character2.Name = player.Name
			playerCharacter = character2Clone
			character2Clone.Parent = game.Workspace
		end
	end
end)
2 Likes

this part on top and bottom should be
player.Character = character1Clone
and
player.Character = character2Clone

1 Like

I’ve tried this. Same issue still occurs.

1 Like

Try using Players:GetPlayers() instead

2 Likes

This did not work either unfortunately.

Oh yeah I see it now, it should be value.Value == 1/2 and not value == 1/2
Also try not to set a variable for the character of the player. Directly set the character to the officer character

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