Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How do you make Zombies spawn at night and die in the day?

Asked by 3 years ago

I have tried so hard to make Zombies spawn at night and die in the day but it is so hard, If anyone knows how to do this that would be helpful as this is key to my game.

0
I'm a noob at scripting but have you tried TimeOfDay or ClockTime under the Lighting tab combined with Humanoid damage? LimitedVxrsion 3 — 3y

1 answer

Log in to vote
0
Answered by
TrippyV 314 Donator Moderation Voter
3 years ago

Assuming that you have a functioning day/night script already made, you can use the GetPropertyChangedSignal event with the ClockTime property of Lighting to achieve what you're looking for.

Once you've connected this event, you can use a debounce to keep the function from firing in later portions of the day.

An application of this can be found below:


local LightingService = game:GetService("Lighting") local TIME_DAY = 6 -- Set this to the hour you want the zombies to die local TIME_NIGHT = 18 -- Set this to the hour you want zombies to spawn local zombiesActive = false -- This is our debounce local function ClockTimeChanged() local newClockTime = LightingService.ClockTime if zombiesActive then -- If zombies are out, lets check if the ClockTime is day. if (newClockTime >= TIME_DAY and newClockTime < TIME_NIGHT) then zombiesActive = false -- PUT YOUR CODE TO DESPAWN THE ZOMBIES HERE end elseif (newClockTime >= TIME_NIGHT or (newClockTime > 0 and newClockTime < TIME_DAY)) then -- If zombies aren't spawned, we check if the ClockTime is night to spawn them. zombiesActive = true -- PUT YOUR CODE TO SPAWN THE ZOMBIES HERE end end LightingService:GetPropertyChangedSignal("ClockTime"):Connect(ClockTimeChanged) -- This is where we are making the connection to listen to when the time is changed. Once the time changes, the ClockTimeChanged function will fire.

The rest here is up to you. I've left comments in caps as indication of where to put your code.

If you have any questions, be sure to ask. Best of luck!

0
Wow it works thanks dude! subblox1234 9 — 3y
Ad

Answer this question