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

How do I randomize my piggy skins in a folder of them?

How do I make it so the piggy skin is randomized in a folder,

   function module.DressPiggy(piggy)

local character = game.ServerStorage.Piggy:Clone()

character.Name = piggy.Name

piggy.Character = character

character.Parent = workspace

end

For example like this before,

   function module.ChoosePiggy(players)

local RandomObj = Random.new()

local chosenPiggy = players[RandomObj:NextInteger(1,#players)]

return chosenPiggy

My main part in my example is the local chosenPiggy = players[randomobj:NextInteger(1#players)]

Would it just be local dressPiggy = game.ServerStorage.#PiggySkins[RandomObj:NextInteger(1,#PiggySkins)]

Please correct me this is essential.

3 comments

0

(Sorry for the bad edit, but idk why it's not showing correctly for me the code blocks)

0

Lol

0

My bad, I'll fix it.

1 answer

✓ Accepted answer

You can use math.random(min, max) to get a random number on a interval, and then select the piggy by the table index

function module.ChoosePiggy(players)
	local chosenPiggy = players[math.random(1,#players)] -- Here we will get a number between 1 and the number of players

	return chosenPiggy
end 

In this case, chosenPiggy will be a player

If this answers your question, pleace mark the answer as accepted

2 comments

0

Not exactly what im looking for, I need a folder that randomly selects the piggy skin from the piggyskin's folder after the piggy is chosen.

0

Just pass the folder childrens as the argument, I assumed it's player because of the variable name

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