Choose random character and apply

Hi, i don’t know how i can make a random character system on spawn when the team of player is “Civil” here is the code template but no topics on what i want to do.

local charsFolder = game:GetService("ServerStorage"):WaitForChild("chars")

local function pickRandomChar()
	local charList = charsFolder:GetChildren()

	return charList[math.random(#charList)]
end

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(char)
		print("added")
		if player.Team == "Civil" then
			local newChar = pickRandomChar()
			--magic here
		end
	end)
end)
2 Likes

Do you want to choose a physical random character ? Like for example a ball ?

A normal character you can see a lot of exemple by typing r15 startercharacter in toolbox

  • Firstly you’ll have to clone the new character ( newChar )
  • Secondly you’ll have to clone some scripts and such from the old character into the new one,
    Those are the following: The humanoid, the animate script.
  • After you’ve done that you will probably have to rename the new character to your player name
    (I do not know if this is exactly needed but I’ve done this in my personal script a while ago as the roblox engine is also generating your character with your name)
  • Then you will want to set player.Character = newChar
  • And lastly you will want to parent newChar to the workspace

I do not know if it’ll work like this for you since this is just a short summary of what I’ve done in my script, and the last time I changed something at it was a year ago. But this is one way you could go at it.

I tryed but here the errors and not works, give you the file(the chars are for exemples).
random char.rbxl (59.1 KB)

math.random(1, #charList)

I saw the error on this line.

There no error in ? It choose correctly see the output.

Ok, add humanoid in StarterPlayer named StarterHumanoid and a model named StarterCharacter and add a base part named HumanoidRootPart and weld it to different parts.

Don’t want any StarterCharacter or that will be not random and not just for 1 team…

Well one thing I’ve noticed is that the character has no animation because you’ve forgotten to clone the animation script into the new character…
This can be fixed with:

char:FindFirstChild("Animate"):Clone().Parent = newChar

The other thing I’ve noticed is that our system work very different from each other…
Mine uses a GUI button to detects when a player wants to morph into a certain body.
Yours will want to work with when the player spawns, therefore there are a lot of characers cloning because as soon you you do player.Character player.CharacterAdded will be fired until roblox rate limits it. Therefor this error gets created:
Maximum event re-entrancy depth exceeded for Player.CharacterAdded

Like I said our system work very differently so I cannot help you to achieve you goal as I have the player manually trigger their change and you’d want it to be automatic and I currently have no idea how to fix the issue with the multiple characters spawning

Now I don’t know how to make the “magic here”

Boost topic

I didn’t found anything on the subject, but that really important for what i want to do.

Fixed everything and it and work now.

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