Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 4 years ago
Edited 4 years ago

Please encode Lua code in the Lua block code tag (look for the Lua icon in the editor).

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.

0
(Sorry for the bad edit, but idk why it's not showing correctly for me the code blocks) Leamir 3138 — 4y
0
Lol Block_manvn 395 — 4y
0
My bad, I'll fix it. AdrianDenisMastter -10 — 4y

1 answer

Log in to vote
1
Answered by
Leamir 3138 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

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

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. AdrianDenisMastter -10 — 4y
0
Just pass the folder childrens as the argument, I assumed it's player because of the variable name Leamir 3138 — 4y
Ad

Answer this question