Hey there, i was tryna make a NPC spawning just at the night and at the day he’s removed, and repeating like that, im not a good scripter so i ran onto some problems.
Day Script
if game.Lighting:GetMinutesAfterMidnight() > 18*60 then
game.ServerScriptService.dValuee.Value = false
if game.ServerScriptService.Valuee.Value = false then
game.Workspace.Wendigo:Destroy()
end
end
Night Script
if game.Lighting:GetMinutesAfterMidnight() < 6*60 then
game.ServerScriptService.Valuee.Value = true
if game.ServerScriptService.Valuee.Value = true then
game.ServerStorage.Wendigo:Clone()
game.ServerStorage.Wendigo.Parent = workspace
end
end
Im seriously bad at scripting and some advice would help, if you want to know what day/night script im using , its the realism plugin one.
1 Like
--Day Script
game.Lighting:GetPropertyChangedSignal("ClockTime"):Connect(function()
if game.Lighting:GetMinutesAfterMidnight() > 1080 then
game.ServerScriptService.Valuee.Value = false
if game.ServerScriptService.Valuee.Value = false then
game.Workspace.Wendigo:Destroy()
end
end
end)
--Night Script
game.Lighting:GetPropertyChangedSignal("ClockTime"):Connect(function()
if game.Lighting:GetMinutesAfterMidnight() < 360 then
game.ServerScriptService.Valuee.Value = true
if game.ServerScriptService.Valuee.Value = true then
game.ServerStorage.Wendigo:Clone()
game.ServerStorage.Wendigo.Parent = workspace
end
end
end)
My guess is that you’re not checking for the conditional check every time the time changes? Try this
I few things I would change in the above post,
- It’s better to use
GetService
to get the services you’re referencing instead of a direct index
- It can be using a single GetPropertyChangedSignal and using an if-elseif statement
- If you’re only wanting to spawn a single Wendigo, you’d have to include the Valuee check in the if-elseif statement, not after
- Put Valuee in a variable as you are referencing it many times for the same of organization
Here’s how I would do it
local ServerScriptService = game:GetService("ServerScriptService")
local ServerStorage = game:GetService("ServerStorage")
local Lighting = game:GetService("Lighting")
local valuee = ServerScriptService.Valuee
local wendigo
Lighting:GetPropertyChangedSignal("ClockTime"):Connect(function()
if Lighting:GetMinutesAfterMidnight() > 1080 and valuee.Value then
valuee.Value = false
wendigo:Destroy()
wendigo = nil
elseif Lighting:GetMinutesAfterMidnight() < 360 and not valuee.Value then
valuee.Value = true
wendigo = ServerStorage.Wendigo:Clone()
wendigo.Parent = workspace
end
end)
1 Like