So if I have a bunch of objects in a model called spreadable and I want it to choose one out of all these children how would I do that?
local Target = script.Parent.Spreadable function makefire(parent) local fire = Instance.new("Fire") fire.Parent = parent end makefire(Target)
In the above I just said Spreadable and the script chose a random one but it continuously chose that same random one each time I ran it.
You can use the method GetChildren to return to you all of the descendants of the model in a table. Then you can use the method random in the math library to pick a random index in the table:
local target = script.Parent.Spreadable local descendants = target:GetChildren() function makefire(parent) local fire = Instance.new("Fire") local index = math.random(1, #descendants) fire.Parent = descendants[index] end makefire(target)
Note that this function will error if #descendants
is less than 1. You can use an if statement to avoid this error if necessary.