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

How would I give this to distribute the candy correctly?

Asked by 10 years ago

I've tried doing this, but cannot figure out how to make the script put out 1 - 10 pieces of candy...

for _,x in pairs (game.Lighting:children())  do
 if x.className == "Part" then
     if x.Name == "Candy" then
        Cloning=x:clone(math.random(1,10)
Cloning:makeJoints()
Cloning.Parent = workspace

end end end

1 answer

Log in to vote
0
Answered by 10 years ago

It depends on how many candies you want to make, but you will need to edit this. Im assuming that the candy is just a part so I shall try my best to fit your needs. You will need to have a model in lighting with the candies in it!

local Candies = game.Lighting.MODELFOLDERNAME:GetChildren()

function SpawnCandies(NumCandies)
for i = 1,NumCandies  do --Spawns NumCandies
local Candy = Candies[math.random(1, #Candies)]:Clone()
Candy.Parent = game.Workspace
end
end

SpawnCandies(1) --Change 1 to the number of candies that you want to spawn.

If you don't understand then let me explain, Candies is a table of objects and when I used the variable Candy it chooses one of the random candies in the Candies variable. It's kinda hard to explain.

Don't forget to mark this as solved and as the correct answer!

Ad

Answer this question