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

My audio is not playing with this time of day script?

Asked by 6 years ago
1NHK = workspace.sss
2night = game.Lighting.TimeOfDay
3 
4if night >= 6 then
5    NHK:Play()
6end

So basically once the time of day turns night (6) then it'll play this song that my variable labeled "NHK". My script is not working for some reason..

1 answer

Log in to vote
0
Answered by 6 years ago
Edited by User#24403 6 years ago

ClockTime and GetPropertyChangedSignal


You would do this by detecting changes to the ClockTime property of the Lighting service, to do this you would use the :GetPropertyChangedSignal function, as the event returned by it only fires when the specified property is changed, rather than all the properties, thus not getting overran by changed events.

ClockTime should be used instead of TimeOfDay in your script as the TImeOfDay property is a string, not a number, which means it can't be compared with other numbers with relational operators. Also, it contains non-digit characters (^%d), which means the tonumber function also won't work. Alernatively, ClockTime is a number value, meaning that it can be compared using relational operators.

1local NHK = workspace.sss
2local lighting = game.Lighting
3lighting:GetPropertyChangedSignal("ClockTime"):Connect(function()
4    if lighting.ClockTime >= 6 then
5        NHK:Play()
6    end
7end

Hopefully this helped!

0
that little space "local NHK" i edited it out User#24403 69 — 6y
0
:GetPropertyChangedSignal is a Signal/method. It fires a Listener. Terminology. Ziffixture 6913 — 6y
0
oh theking48989987 2147 — 6y
0
Also you forgot to add "end)" because when you use (function() you always need it to end with "end)" a minor mistake but it's alright FearlessX96 74 — 6y
Ad

Answer this question