I’m trying to make a script that when os.date is equal to the cooldown value it will stop the cooldown value and reset an IntValue.
My script doesn’t print anything even after I break the loop and os.date is equal to the coolDown Value.
I haven’t done much. I’ve tried breaking the loop first, but it still didn’t work.
Code
--This is a server script--
game.Players.PlayerAdded:Connect(function(player)
local skipStagesLeft = 0
local timeLeft = player:WaitForChild("TimeTellReset")
while wait(1) do
if skipStagesLeft == 0 then
timeLeft.Value = os.date("%d") + 1
print("User has run out of their daily skips! Starting countdown...")
break
end
end
while skipStagesLeft == 0 do
wait(1)
if timeLeft.Value == os.date("%d") then
skipStagesLeft = 2
print("User has waited 24 hours! Adding SkipStageValue...")
end
end
end)
--This is a server script--
game.Players.PlayerAdded:Connect(function(player)
local skipStagesLeft = 0
local timeLeft = Instance.new("IntValue", workspace) -- I'm aware of the fact that it might work in a different way
while wait(1) do
if skipStagesLeft == 0 then
timeLeft.Value = os.date("%d") + 1
print("User has run out of their daily skips! Starting countdown...")
break
end
end
while skipStagesLeft == 0 do
wait(1)
if timeLeft.Value == os.date("%d") then
skipStagesLeft = 2
print("User has waited 24 hours! Adding SkipStageValue...")
end
print("TimeLeft: ", timeLeft.Value)
print("Os Time:", os.date("%d"))
end
end)
My result:
I suggest doing that because I could experience different results and reduce cooldown for testing purposes.
I found something. This is my code for testing (reduced cooldown to one minute):
--This is a server script--
game.Players.PlayerAdded:Connect(function(player)
local skipStagesLeft = 0
local timeLeft = Instance.new("IntValue", workspace) -- I'm aware of the fact that it might work in a different way
while wait(1) do
if skipStagesLeft == 0 then
timeLeft.Value = os.date("%M") + 1
print("User has run out of their daily skips! Starting countdown...")
break
end
end
while skipStagesLeft == 0 do
wait(1)
if timeLeft.Value == os.date("%M") then
skipStagesLeft = 2
print("User has waited 24 hours! Adding SkipStageValue...")
end
print("TimeLeft: ", timeLeft.Value)
print("Os Time:", os.date("%M"))
print(timeLeft.Value == os.date("%M"))
print()
end
end)
Look at the output:
When TimeLeft and OsTime are equal to 46, somehow timeLeft.Value == os.date("%M") condition is still false.
EDIT: I had to edit my last post because I couldn’t upload 3 post without someone answering my posts. So this is I think the wanted solution:
By using typeof() I found out that timeLeft.Value is a number and os.date("%M") is a string. I changed the condition to print to timeLeft.Value == tonumber(os.date("%M")) and I got the expected result:
So the second if statement should be changed to: if timeLeft.Value == tonumber(os.date("%d")) then