Hello there, I want to make a script that triggers something at a certain time of the day.
but for some reason, it didn’t work it just does not trigger
here the script:local Periode = 4
while wait() do
game:GetService('Lighting').ClockTime = game:GetService('Lighting').ClockTime + 0.1
local JOURSEMAINE = JOURS[JourDeCommencement]
-- print('Test')
--rint(CLASSE)
--print(CLASSE[JourDeCommencement])
if Periode == 4 then
-- print('Test')
if LIGHTING.ClockTime == 8 then
print('period 1 commence dans 5 minute')
if LIGHTING.ClockTime == 10 then
print('Pediode 1 fini')
end
end
end
end
I’m really tired right now so maybe that’s why my scripting isn’t the best but thx if y’all help
Since you are checking if the clock time is 8, there is no way it will be 10 inside the if statement. I guess what you meant to do was this:
-- print('Test')
if LIGHTING.ClockTime == 8 then
print('period 1 commence dans 5 minute')
elseif LIGHTING.ClockTime == 10 then
print('Pediode 1 fini')
end
Avoid using while wait() do it is more common practice to do this instead:
while true do
task.wait();
end;
Don’t get the service every iteration. I see that you already have a variable named “LIGHTING” which I guess is the lighting service. Because of this I recommend replacing game:GetService("Lighting") with “LIGHTING”
You can also do this instead since it makes it more readable:
If you mean math.floor to floor the clock time then it wouldn’t cut it since you are adding decimal values each time. These decimal values would make it so if you floor the value it will never increase since it will try to add a decimal value and be rounded.
However you can indeed use math.floor for the check:
-- print('Test')
if(math.floor(LIGHTING.ClockTime) == 8) then
print('period 1 commence dans 5 minute')
elseif(math.floor(LIGHTING.ClockTime == 10) then
print('Pediode 1 fini')
end
However, the above would make it so that it would fire multiple times each iteration. Because of this I want to ask you why are you adding decimal values in clock time? Instead of adding something like 0.01 or so.
I see, maybe you are just starting with an ambiguous value. Check if Lighting is starting with something like 0.392103 on workspace since that could also cause this problem.
I am seeing the problem, roblox is probably counting wrongly like all computers do. It is something related with the fact that binary can only use 2 digits. The problem is similar to something like us trying to represent 1/3 which would be 0.333333333333333…
This is what I mean:
The solution, now that you are sure there aren’t 2 counters going on at the same time is to use math.ceil like you suggested. In this case we are not using math.floor since we are counting up and not downwards.