Play sound once a certain clocktime

The sound doesn’t play when it hits 12 o’clock. I’ve been searching and none of the solutions worked for me

local Bell = workspace.ClockMain.Bell
local Lighting = game:GetService'Lighting'

Lighting:GetPropertyChangedSignal'ClockTime':Connect(function()
	local Time = Lighting.ClockTime
	while true do
		wait()
		if Time == 12 then
			Bell.Playing = true
		end
	end
end)

To make clear, the sound isn’t looped cause I dont need it looped.

This goes in scripting support

  • The function you connected will run every single time the clocktime is changed, so there isn’t a need for a loop.
  • Clocktime doesn’t update automatically so unless you have another script constantly changing it, it will stay at what it is set to before runtime.
  • The time could jump from 11.99 to 12.01, you may want to widen the range the bell can play a bit and add a debounce so it doesn’t then play twice.
1 Like

You probably need to be a little less specific with your Time.
When you say if Time == 12 then and Time = 12.00001 it won’t work.
Try something like if Time >= 12 then and set up a debounce Boolean to let you know if the sound isn’t already playing.
I’d try putting if Time >= 12 and Time < 12 + (whatever your time sound length is) so it won’t keep checking anything outside this time frame

1 Like

this actually worked! thanks!

local Bell = workspace.ClockMain.Bell
local Lighting = game:GetService'Lighting'
local debounce = false

Lighting:GetPropertyChangedSignal'ClockTime':Connect(function()
	local Time = Lighting.ClockTime
		if Time >= 12 and debounce == false then
			debounce = true
			Bell.Playing = true
		elseif Time <= 12 and debounce == true then
			debounce = false
		end
	end
end)

You may want to try this:

local Bell = workspace.ClockMain.Bell --I'm guessing this is the sound name
local Lighting = game:GetService'Lighting'
local debounce = false
length = (the length of time the sound takes to play, going slightly longer shouldn't make a difference

Lighting:GetPropertyChangedSignal'ClockTime':Connect(function()
	local Time = Lighting.ClockTime
		if debounce == false and Time >= 12 and Time <= (12 + length) then
			debounce = true
			Bell:Play()     -- plays the sound
            task.wait(length)
		end
        debounce = false
	end
end)

[/quote]
Your outher script was double checking the exact same information with the elseif which wasn’t required.
This way it gets the first check to see if the time is 12 or later, plays the sound, waits the length of time the sound

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.