Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to select a random character for appearance override?

Hello, I have created 4 player models hat I want to act as "Default" characters for my game. To try and do this, I set up this script:

local characters
local clone

function onPlayerEntered(player)
	characters = math.random(4)
		if characters == 1 then
		clone = script.StarterCharacter1:Clone()
		clone.Name = "StarterCharacter"
		clone.Parent = game.StarterPlayer
	elseif characters == 2 then
		clone = script.StarterCharacter2:Clone()
		clone.Name = "StarterCharacter"
		clone.Parent = game.StarterPlayer
	elseif characters == 3 then
		clone = script.StarterCharacter3:Clone()
		clone.Name = "StarterCharacter"
		clone.Parent = game.StarterPlayer
	elseif characters == 4 then
		clone = script.StarterCharacter4:Clone()
		clone.Name = "StarterCharacter"
		clone.Parent = game.StarterPlayer
	end

	end
	
	game.Players.PlayerAdded:connect(onPlayerEntered)

The problem is that every player has the same character, I want there to be a mix of the 4 characters I have created

1 comment

0

This is a very simple error with your scipt. the characters = math.random(4) is wrong and should be characters = math.random(1,4)

1 answer

You can use math.randomseed(tick()) in the first line of your script to generate new random seed every time

Also, use math.random(1,4) to generate number from 1 to 4

1 comment

0

Good job. Exactly what OP wanted

This discussion is preserved as it was. New answers, comments, and votes are closed.