Script not Working

Alien Spawning script not working

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

PLS HELP

Any errors in the output by chance?

no there is not… what should I do

Does the script look good to you?

1 Like

What exactly isnt working though

The aliens are not spawning. that’s the only thing this script does

Where is this script located if you dont mind me asking

game.ServerScriptService

Normal Script

You do have an alien in ServerStorage, correct? And make sure it isn’t invisible or anything like that, worth it to double check. Screenshots are helpful.

Well he said there are no errors it would say it couldn’t find the alien

On The Left


It could just be me (programming is not my strong point), but the area at the bottom seems like it might be the source of your issue:

Didn’t you already state that “AlreadySpawned” is false at the beginning?

Thats not the issue, it is changing the value back to false (usually it will be true because of the if statement before it, and it doesn’t matter regardless)

Sorry, like I stated earlier, programming is not my strong point.

I would check the opacity of the alien and make sure the location is set to origin and anchored (or not, depending). Could you also screenshot the console output when running the game?

edit: Also check the clocktime and make sure it is the correct value, I am not familiar with it but if that is the wrong value the first if statement won’t trigger at all.

I found and fixed the problem, the new problem is that the aliens are spawning in the same spot, and attacking themselves. How do I make them spawn randomly

You would need to define several spawn points and loop through each alien, choosing a spawn point randomly. You could put the spawn points in a table, and use that. If you only want one alien per spawn, remove the spawn from the table once you spawn the alien. You don’t have to use tables, just an idea.

I will add a different topic for that.