Script Addition Help

I have this script, it works, but all of the Aliens spawn at “0, 0, 0” and at the same spot, They also attack each other. How would I make the aliens spawn randomly around the surface of the map, and not attack each other??

local Alien = game.ServerStorage.Alien
local AlienAmount = 300

local SpawnedAliens = {}
local AlreadySpawned = false
while true do
	if (game.Lighting.ClockTime < 5 or game.Lighting.ClockTime > 18) and not AlreadySpawned then
		AlreadySpawned = true
		for i = 1, AlienAmount do
			local AlienClone = Alien:Clone()
			AlienClone.Parent = workspace
			table.insert(SpawnedAliens, AlienClone)
			wait(0.25)
		end
	elseif not (game.Lighting.ClockTime < 5 or game.Lighting.ClockTime > 18) and AlreadySpawned == true then
		if #SpawnedAliens > 0 then
			for i,v in pairs(SpawnedAliens) do
				if v ~= nil then
					v:Destroy()
				end
			end
		end
		AlreadySpawned = false
	end
	wait(1)
end
2 Likes

You don’t mention anywhere “AlienClone:SetPrimaryPartCFrame”. They’ll obviously spawn at the same place.

… Where would I add that in?

This part, make a new line and enter:

AlienClone:SetPrimaryPartCFrame(CFrame.new(Vector3.new(math.random(0,100), 0, math.random(0, 100))))

The middle 0, you can make it bigger if you want to make aliens spawn at more upper and you can change 100’s to add more randomity

Like that, change the num1, num2 by the area limits (X/Z) and heightPosition by the actual height the map is in

1 Like

my new script doesn’t work either

local Alien = game.ServerStorage.Alien
local AlienAmount = 300

local SpawnedAliens = {}
local AlreadySpawned = false
while true do
	if (game.Lighting.ClockTime < 5 or game.Lighting.ClockTime > 18) and not AlreadySpawned then
		AlreadySpawned = true
		for i = 1, AlienAmount do
			local AlienClone = Alien:Clone()
			AlienClone:SetPrimaryPartCFrame(CFrame.new(Vector3.new(math.random(50,500), 0, math.random(50, 500))))
			AlienClone.Parent = workspace
			table.insert(SpawnedAliens, AlienClone)
			wait(0.25)
		end
	elseif not (game.Lighting.ClockTime < 5 or game.Lighting.ClockTime > 18) and AlreadySpawned == true then
		if #SpawnedAliens > 0 then
			for i,v in pairs(SpawnedAliens) do
				if v ~= nil then
					v:Destroy()
				end
			end
		end
		AlreadySpawned = false
	end
	wait(1)

end

Whats the error you just gave me the script without any errors

The Aliens are not spawning randomly

They dont spawn randomly i understand, but then where they spawn?

I cant find them, yes I do have a time script

Find your alien model at properties there is primary part property click it and set it to humanoidrootpart inside your alien model.

1 Like

humanoidrootpart doesn’t exist, that might be the problem

Send me a screenshot of the explorer so i can see it

Set the primary part property to Torso

how exactly?? idk how… help!

Click alien model go to properties tab find PrimaryPart there then click it, go to explorer tab find “Torso” part that is in the alien model

okay its done, what next???

Run the game again to see if the aliens spawn randomly

1 Like

They do not, If it helps, the script is in game.ServerScriptService normal script