local pathpart = workspace.IslandParts.islandpaths.islandpath for i,pathpart in pairs(pathpart.Parent:GetChildren()) do if pathpart.Name == "islandpath" then local palmgen= math.random(30) if palmgen == 2 then print("PALM GEN IS: ",palmgen) local palm = game.ReplicatedStorage.Assets.islandnature.palm:Clone() palm.Parent = workspace palm:MoveTo(pathpart.Position) else print("PLAM GEN IS: ",palmgen) end end end
Facilities should create a random object if palmgen = 2, but math.random ALWAYS produces the same random numbers. How to make this feature really random?
You need to warm the pseudo random generator by using math.randomseed(x)
. Where x
is the seed for the generator. One of the most common ways for warming it up is to use tick()
as the input. Applying this to your script would make it into.
local pathpart = workspace.IslandParts.islandpaths.islandpath math.randomseed(tick()) for i,pathpart in pairs(pathpart.Parent:GetChildren()) do if pathpart.Name == "islandpath" then local palmgen= math.random(30) if palmgen == 2 then print("PALM GEN IS: ",palmgen) local palm = game.ReplicatedStorage.Assets.islandnature.palm:Clone() palm.Parent = workspace palm:MoveTo(pathpart.Position) else print("PLAM GEN IS: ",palmgen) end end end