Whenever I launch my game it always clones multiple npc and I just want it to clone one.
Sciript: if game.Lighting.TimeOfDay == "20:00:00" then local Monster = game.ReplicatedStorage.NPC:Clone() Monster.Parent = workspace end
The reason why your NPC is spawning more than 1, is because the script keeps checking if the TimeOfDay
is 20:00:00.
01 | local canSpawn = false |
02 | local debounce = false |
03 |
04 | function loadNPC() |
05 | if canSpawn then |
06 | local Monster = game.ReplicatedStorage.NPC:Clone() |
07 | Monster.Parent = workspace |
08 | end |
09 | end |
10 |
11 | game.Lighting.Changed:Connect( function () |
12 | if game.Lighting:GetMinutesAfterMidnight() = = 1200 then -- better way of checking time |
13 | if not debounce then |
14 | debounce = true |
15 |
That should work, I tested it in studio. Please accept the answer if you found this a solution
it will clone until is 20:00:01, you can try adding a loop with a delay between them, i think it will work like that
1 | if game.Lighting.TimeOfDay = = "20:00:00" then |
2 | while true do |
3 | local Monster = game.ReplicatedStorage.NPC:Clone() |
4 | Monster.Parent = workspace |
5 | Wait( 5 ) |
6 | end |
7 | end |
or like this
01 | local debounce = 1 |
02 | if game.Lighting.TimeOfDay = = "20:00:00" then |
03 | if debounce = = 1 then |
04 | while true do |
05 | local Monster = game.ReplicatedStorage.NPC:Clone() |
06 | Monster.Parent = workspace |
07 | Wait( 5 ) |
08 | debounce = 0 |
09 | end |
10 | end |
11 | end |