Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 9 years ago
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

0
You can't compare strings with >=. I'll give you the finished script later. aquathorn321 858 — 9y
0
Try and look up 'String Patterns' on the Roblox Wiki. It'll help you a lot with this. DigitalVeer 1473 — 9y

3 answers

Log in to vote
1
Answered by 9 years ago

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

Ad
Log in to vote
0
Answered by 9 years ago

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
Log in to vote
0
Answered by 9 years ago

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

Answer this question