Hello! For some reason, my while true do loop is stuck at one if statement. Even when I set the ClockTime to 20, it keeps printing “No”
local isDay
while true do
wait(1)
if game:GetService("Lighting").ClockTime > 17 then
isDay = true
print("Yes")
elseif game:GetService("Lighting").ClockTime < 17 then
isDay = false
print("No")
end
end
wait(1)
if game:GetService("Lighting").ClockTime > 17 then
isDay = true
print("Yes")
elseif game:GetService("Lighting").ClockTime < 17 then
isDay = false
print("No")
end
First off, you shouldn’t use a a loop to check properties in the first place. Use events, they’re much more efficient.
local timeChange = game:GetService("Lighting"):GetPropertyChangedSignal("ClockTime")
timeChange:Connect(function()
--time changed
end)
Now, you should try changing “elseif” to just “else” in your if statement.
local timeChange = game:GetService("Lighting"):GetPropertyChangedSignal("ClockTime")
timeChange:Connect(function()
if game:GetService("Lighting").ClockTime . 17 then
print("yes")
else
print("no")
end
end)
Try this, and see if it works.
Edit: I added an end I forgot to put in. Try the new code.
I tested the script and it worked fine for me, so I can only assume that you’re changing the property on the client and not the server, if you’re using this in a server script – anything done on the client will not replicate, but of course there’s a few exceptions