I am trying to make zombies spawn in random locations (there are 4 at the moment) and they always spawn at the same place. I tried making this custom function to try to make numbers more random but it is not working.
Every time I do a new test session in studio the number changes but it always repeats the same number.
function GetRandom(Num1, Num2) local Nums = {} math.randomseed(tick()) for i = 1,100 do local Math1 = math.random(Num1,Num2) Nums[i] = Math1 end local Math2 = math.random(1,100) return Nums[Math2] end module.PrepareZombie = function(Name) local Zombie = Zombies[Name]:Clone() Zombie.Parent = ZombieFolder local Spawn = GetRandom(1,#Spawns:GetChildren()) print(Spawn) Spawn = Spawns:GetChildren()[Spawn] Zombie.HumanoidRootPart.CFrame = Spawn.CFrame ZombieCore.Reincarnate(Zombie) end
Use math.randomseed( tick() )
math.randomseed() sets the "seed" for math.random. As long as this number is different, your values will be.
tick() fetches the number of seconds elapsed since January 1st 1970. This will always be a different number, so your list of numbers will always be unique.