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 5 years ago
NHK = workspace.sss
night = game.Lighting.TimeOfDay

if night >= 6 then
    NHK:Play()
end

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 5 years ago
Edited by User#24403 5 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.

local NHK = workspace.sss
local lighting = game.Lighting
lighting:GetPropertyChangedSignal("ClockTime"):Connect(function()
    if lighting.ClockTime >= 6 then
        NHK:Play()
    end
end

Hopefully this helped!

0
that little space "local NHK" i edited it out User#24403 69 — 5y
0
:GetPropertyChangedSignal is a Signal/method. It fires a Listener. Terminology. Ziffixture 6913 — 5y
0
oh theking48989987 2147 — 5y
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 — 5y
Ad

Answer this question