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

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

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

✓ Accepted answer

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!

4 comments

0

that little space "local NHK" i edited it out

0

:GetPropertyChangedSignal is a Signal/method. It fires a Listener. Terminology.

0

oh

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

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