Random Starter Character Not Working as Intended

I would like my Avatar to not be present when playing.

I can’t get My avatar to go away and be Replaced with one of the other 9 Avatars

The Random Avatar just gets Stuck inside of The Player and makes it Incredibly hard to Walk & Jump

game.Players.PlayerAdded:Connect(function(plr)
	local Characters =
		game:GetService("ReplicatedStorage").Players:GetChildren()[math.random(1,9)]
	
	if game:GetService("StarterPlayer"):FindFirstChild("StarterCharacter")
then
	
	game:GetService("StarterPlayer").StarterCharacter:Destroy()
end

Characters.Name = "StarterCharacter"
Characters.Parent = game:GetService("StarterPlayer")
plr.CharacterRemoving:connect(function(char)
	Characters =
		game:GetService("ReplicatedStorage").Players:GetChildren()[math.random(1,9)]
	
	if 
		game:GetService("StarterPlayer"):FindFirstChild("StarterCharacter") then
		game:GetService("StarterPlayer").StarterCharacter:Destroy()
	end
	Characters.Name = "StarterCharacter"
	Characters.Parent = game:GetService("StarterPlayer")
	end)
end)

This is the only Error I’ve gotten.

1 Like

For me, there are no errors with your script. I organized it and it works perfectly fine?

game.Players.PlayerAdded:Connect(function(plr)
	local Characters = game:GetService("ReplicatedStorage").Players:GetChildren()[math.random(1,9)]

	if game:GetService("StarterPlayer"):FindFirstChild("StarterCharacter") then
		game:GetService("StarterPlayer").StarterCharacter:Destroy()
	end

	Characters.Name = "StarterCharacter"
	Characters.Parent = game:GetService("StarterPlayer")
	
	plr.CharacterRemoving:connect(function(char)
		Characters = game:GetService("ReplicatedStorage").Players:GetChildren()[math.random(1,9)]
		if game:GetService("StarterPlayer"):FindFirstChild("StarterCharacter") then
			game:GetService("StarterPlayer").StarterCharacter:Destroy()
		end
		Characters.Name = "StarterCharacter"
		Characters.Parent = game:GetService("StarterPlayer")
	end)
end)
1 Like

That works, although the programming isn’t that great. I would use:

game.Players.PlayerAdded:Connect(function(player)
	
	player.CharacterAdded:Connect(function(char)
		
          local rand = math.random(1, 9)

		if not game.StarterPlayer:FindFirstChildWhichIsA("Model") then
			
			for i, v in pairs(game.ReplicatedStorage.Players:GetChildren())do

				local isChosen = Instance.new("IntValue", v)
				isChosen.Name = i

				print(rand)

				if v:FindFirstChild(rand) then

					char:Destroy()

					local clone = v:Clone()
					clone.Parent = game.StarterPlayer

					player:LoadCharacter()


				end

			end
			
		end
		
	end)
	
end)
1 Like

Ah, nevermind.

This is serverbased only, which means all of the players will have the same avatar.

@The1770s, if you want to fix this then I recommend using the code above, or just redoing it with a few remote events (just to organize it better).

1 Like

The Problem is, I’m not great at Coding and I can’t find anything helpful on how to do this Properly

Thanks for all the Help though.

I’ll try to use the Method you sent me in the Morning.

@FyreeIG

This didn’t seem to work for me. I didn’t get any Errors. but the same Glitchy thing where I get stuck in another StarterCharacter keeps happening. (Screenshot in my Post)

It’s most likely your game/any scripts in your game, network issues, or your avatar.