So I’ve had a script which randomly selects an enemy based off of a random number and decides a random place to insert said enemy.
Now for some weird reason, the math.random part of the script seems to not be working anymore (it generates the same random number for the chosen enemy and the same random number for the chosen location (X and Z)
Here’s the full script:
wait (5)
local spawns = script.Parent.Spawns:GetChildren()
local maxCount = 100 -- how many enemies to generate in total
local count = 0
RunService = game:GetService("RunService")
if RunService:IsStudio() then -- makes it easier on your computer if you test script in studio
maxCount = 5
end
local Spawntime = 1
local Name = script.Parent.Name
local Templates = game.ServerStorage:WaitForChild("TemplateEnemies")
local Area = Templates:WaitForChild(Name)
for _, child in ipairs(spawns) do
child.Transparency = 1
end
while count < maxCount do -- The problems are localized in this part:
local randomspawn = spawns[math.random(1, #spawns)]
local spawnmaxX = randomspawn.Position.X + (randomspawn.Size.X / 2)
local spawnminX = randomspawn.Position.X - (randomspawn.Size.X / 2)
local spawnmaxZ = randomspawn.Position.Z + (randomspawn.Size.Z / 2)
local spawnminZ = randomspawn.Position.Z - (randomspawn.Size.Z / 2)
local spawnY = randomspawn.Position.Y
local AreaTemplates = Templates:WaitForChild(Name)
local selection = math.random(1, #AreaTemplates:GetChildren())
local toclone = Templates:WaitForChild(Name):WaitForChild(selection)
local ranx = math.random(spawnminX, spawnmaxX)
print (ranx)
local ranz = math.random(spawnminZ, spawnmaxZ)
print (ranz)
local Clone = toclone:Clone()
Clone.Parent = script.Parent
Clone:SetPrimaryPartCFrame(CFrame.new(ranx, spawnY, ranz))
count = count + 1
end
And this is what the output of the positioning looks like:
My question is: how could I make it so that the math.Random is actually random