Spawn bug with ClockTime

Hey.

I’ve had a small issue with spawning in.

The scripts should be clear enough.
issue: once the count is on 5, it’ll still continue and the count never resets.

--workspace handler
local count = 1

script.clockTimeEvent.Event:Connect(function()
	repeat 
		game:GetService("ServerStorage").spawnAlien.Part:Clone().Parent = game:GetService("Workspace")
		count += 1
		print(count)
		wait(1)
	until count == 5
end)

image

--serverscriptservice script
local RunService = game:GetService("RunService")
local Lighting = game:GetService("Lighting")
local Players = game:GetService("Players")
local HttpService = game:GetService("HttpService")
local WorkspaceService = game:GetService("Workspace")
local clockTimeEvent = WorkspaceService.WorkspaceHandler:WaitForChild("clockTimeEvent")

Lighting:GetPropertyChangedSignal("ClockTime"):Connect(function()
	local clockTime = Lighting.ClockTime
	
	if clockTime >= 11.9 and clockTime <= 12 then
		clockTimeEvent:Fire()
		print("Fired")
	end
end)

Any help is appreciated.

Try checking if count is greater than or equal to 5 and make it reset after the loop?

local count = 1

script.clockTimeEvent.Event:Connect(function()
	repeat 
		game:GetService("ServerStorage").spawnAlien.Part:Clone().Parent = game:GetService("Workspace")
		count += 1
		print(count)
		wait(1)
	until count >= 5
	count = 1
end)

I do not think that worked.


Maybe make it so it only starts spawning when count is 1?

local count = 1

script.clockTimeEvent.Event:Connect(function()
	if count ~= 1 then
		return
	end
	repeat 
		game:GetService("ServerStorage").spawnAlien.Part:Clone().Parent = game:GetService("Workspace")
		count += 1
		print(count)
		wait(1)
	until count >= 5
	count = 1
end)

So that way if it fires before spawning is done, it just wont do anything

That worked!

Going to test this out with more clocktime and reach back to you with more (possible) errors.

1 Like

Works 100% and I tried it.

Everything went successful.

Thank you so much. Enjoy the rest of your day.

1 Like