How to make things spawn and disappear at certain times

Okay, so i’m currently building a lobby in my game, and the game has a day and night cycle, when the time of day reached a certain point (around dusk) fireflies spawn, i got the fireflies covered, just need help making them spawn in at around dusk and disappear at around early morning.

3 Likes

You can just do basic condition checks on whether the time is equal to a certain time or not.

If or else spawn the part or despawn it

I had a general idea how to do it, just didn’t know how to execute it.

you just do the funny thing like

if clock time < 12 then --spawn fireflies

if clock time >= 12 then --fireflies disappear

1 Like

Yeah, i forgot a good portion of scripting because i haven’t done it since early 2021

I should also make note that the fireflies are a particle emitter with a light inside it

then just make a for i function that loops through each children (fireflies) and enable the particle emitter and light parts

Okay, that is simpler, i’ll try that out

local lighting = game:GetService("Lighting");

local On = false

lighting:GetPropertyChangedSignal("ClockTime"):Connect(function()
	local ct = lighting.ClockTime;
	if (ct <= 6 or ct >= 18) then
		On = true -- do stuff
	else
		On = false -- undo stuff
	end
end)
1 Like

The fireflies consist of a point light and a particle emitter

local lighting = game:GetService("Lighting")

local On = false

lighting:GetPropertyChangedSignal("ClockTime"):Connect(function()
	local ct = lighting.ClockTime;
	if (ct <= 6 or ct >= 18) then
	    On = true -- do stuff
        game.Workspace.Fireflies.PointLight.Enabled = true
        game.Workspace.Fireflies.ParticleEmitter.Enabled = true
	else
		On = false -- undo stuff
        game.Workspace.Fireflies.PointLight.Enabled = false
        game.Workspace.Fireflies.ParticleEmitter.Enabled = false
	end
end)

Put this into server script service, and change the parent stuff as needed

1 Like