Help with the script

Hi! I wanted to make the music change day and night. I made a script like that, but ‘Sound2’ doesn’t change after 6:30 PM and ‘Sound1’ plays all the time without stopping. How to fix it? (The sounds are the children of the script)

‘’’
local lighting = game:GetService(“Lighting”)

local sound1 = script:WaitForChild(“Sound1”)

local sound2 = script:WaitForChild(“Sound2”)

sound1.Looped = true

sound2.Looped = true

sound1:Play()

local function onTimeChanged()

if Lighting.ClockTime == “18:30:00” then

sound1:Stop()

wait(.1)

sound2:Play()

elseif lighting.ClockTime == “07:00” then

sound2:Stop()

wait(.1)

sound1:Play()

end

end

lighting:GetPropertyChangedSignal(“ClockTime”):Connect(onTimeChanged)
‘’’

1 Like

The ClockTime property is not a string; it’s a number. Use lighting.TimeOfDay if you want to keep the string.

1 Like

How you make the script effect is to use the tickmarks above the tab button.

Clock time will never equal “07:00” or “18:30:00”, so none of the code in the if or else statement will ever run. Because clock time is a number, I would also recommend a statement that uses >= and/or <=, just in case clock time skips the numbers you’re looking for currently.