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

Time-of-day song playlist - Simple script not working?

local timeVar = game.Lighting.TimeOfDay

if timeVar >= "7:30:00" then
	script.Dawn.Play()
	script.Sunset.Stop()
elseif timeVar >= "20:00:00" then
	script.Sunset.Play()
	script.Dawn.Stop()
end

The songs don't play at all with no error, so it must mean they didn't even trigger?

Dawn & Sunset are two sounds within the script that is written on.

Thanks

2 comments

0

You can't compare strings with >=. I'll give you the finished script later.

0

Try and look up 'String Patterns' on the Roblox Wiki. It'll help you a lot with this.

3 answers

You could also use: local minutes_after_midnight = game:GetService("LightingService"):GetMinutesAfterMidnight()

You can't compare string values with greater than or equal to, because they're strings, not numbers. You can, however, convert the strings to numbers and compare them.

Finished Script

local time = game.Lighting.TimeOfDay
local t = tonumber(string.sub(time,1,2)..string.sub(time,4,5)..string.sub(time,7,8)) --convert time to a number

if t >= 73000 then
script.Dawn.Play()
script.Sunset.Stop()
elseif t >= 200000 then
script.Sunset.Play()
script.Dawn.Stop()
end

Use tonumber()

First of all, pretty much like aqua said, you can't compare it to string.

But the tonumber() will change your string into actual numbers.

Let me show you an example of tonumber(), along with chatted event (I kind of like chatted event :D)

Number = 123
game.Players.PlayerAdded:connect(function(plr)
plr.Chatted:connect(function(msg)
if msg == "123" then
msg = tonumber(Number)
end

I'm pretty sure this is a working example

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