Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Can someone explain to me how to implement hours that show on the time left?

TimeDaily.OnClientEvent:Connect(function(Jury)
	print(Jury)
	local ClaimText = script.Parent.ClaimButton.TextLabel
	local Zephyr = 86400 - Jury
	local PreMinutes = Zephyr / 60
	local PreSeconds = Zephyr % 60
	local Hours = Zephyr % 86400
	local Minutes
	local Seconds
	if PreMinutes < 10 then
		Minutes = "0"..PreMinutes
	else
		Minutes = PreMinutes
	end
	if PreSeconds < 10 then
		Seconds = "0"..PreSeconds
	else
		Seconds = PreSeconds
	end
	
	ClaimText.Text =  "Time Left: "..math.floor(Minutes)..":"..(Seconds)
	wait(2)
	ClaimText.Text = "Claim!"
end)

https://gyazo.com/1d2874f52f9de83f66d6c57fe4a497f3

2 comments

0

seconds = 60 * 60 * 24; minutes = seconds / 60; hours = minutes / 60; print( string.format("%d:%d:%d", hours, minutes % 60, seconds % 60) ) where 60 * 60 * 24 is 24 hours in seconds

0

should also use os.time(). os.time() + 60 * 60 * 24 is equal to 24 hours from the current time. nextDailyAward = os.time() + 60 * 60 * 24 then your time left would be x = nextDailyAward - os.time(). so minutes = x / 60; hours = minutes / 60

1 answer

✓ Accepted answer

how about use this easy way?

function GetDateTime()
	local temp = os.date("*t")
	local str = ""  -- = temp.year .. ""
	--str = str .. (temp.month < 10 and "0" or "") .. temp.month
	--str = str .. (temp.day < 10 and "0" or "") .. temp.day
	--str = str .. " "
	--str = str .. (temp.hour < 10 and "0" or "") .. temp.hour
	--str = str .. ":"
	str = str .. (temp.min < 10 and "0" or "") .. temp.min
	str = str .. ":"
	str = str .. (temp.sec < 10 and "0" or "") .. temp.sec
	return str
end

-- whatever loop or event you want the follow line to be updated.
ClaimText.Text = GetDateTime()

This discussion is preserved as it was. New answers, comments, and votes are closed.