Hi! I wrote this bit of code that does work as intended, as it’s supposed to generate 1-9 items on a random node. However, there’s this weird quirk where it repeats infinitely. It doesn’t happen repeatedly, just has a small chance of happening. Random of sorts, so I think I might have done something wrong with math.random?
-- local Nodes = script.Parent.nodes:GetChildren() local items = script.Parent.items items.Parent = game.Lighting local Supply = items.Supply:GetChildren() wait(0.1) function UpdateNodes() local Generated = 1 local Amount = math.random(1,9) repeat local Chosen_node = Nodes[math.random(#Nodes)] local Supply_item = Supply[math.random(#Supply)]:Clone() wait() Chosen_node.Transparency = 1 Supply_item.Parent = Chosen_node Supply_item.CFrame = Chosen_node.CFrame * CFrame.new(0,0.2,0) Generated = Generated + 1 print("ITEM SPAWNED AT: " .. Chosen_node.Name) print("Amount Generated:" .. Generated) until Generated == Amount end UpdateNodes()
If someone could point me in the right direction that would be great. Thanks ahead of time!