So it works normally when the script finds that the value is 0, however, once that happens, it just repeatedly calls the function.
(Yes I know the 0 is in quotes, thats by design)
while true do
local freq955Length = game.ReplicatedStorage.radioStations.station995.timeLength.Value
if stationStorage.station995.timePosition.Value == "0" then
update955()
wait(1)
else
print("no")
end
wait()
end
while true do
local freq955Length = game.ReplicatedStorage.radioStations.station995.timeLength.Value
if stationStorage.station995.timePosition.Value == "0" then
update955()
break
else
print("no")
end
wait()
end
Yeah, I honestly don’t know what to do here. Using break literally breaks everything inside of the if-then statement, and if you don’t use a break, the function just gets called continuously when the value is 0.
Sounds like youd need a debounce here. Whenever the value hits 0 turn your debounce to true. And reset it whenever you need it again.
Forgot to add. This will only run the function if your debouce(In my case the called variable) is set to false.
Example:
local Something = 0
local Called = false
local function DoStuff()
end
while true do
Something = Something + 1
if Something == 5 and not Called then
Called = true
DoStuff()
end
task.wait(1)
end
Am I changing the debounce in the right place? I try this and it just continuously calls the function again.
local stationStorage = game.ReplicatedStorage.radioStations
local marketplaceService = game:GetService("MarketplaceService")
local Called = false
local freq955 = {
9112960766, 9113662071
}
--[[local freq955 = {
10790300515, 10790355109, 10790434741, 10790378585
} -- (R&B)
]]
local function update955()
print("function called")
local newSound = freq955[math.random(1, #freq955)]
stationStorage.station995.Sound.SoundId = "rbxassetid://"..newSound
local songName = marketplaceService:GetProductInfo(newSound).Name
stationStorage.station995.songName.Value = tostring(songName)
stationStorage.station995.soundID.Value = tostring(newSound)
print("Song ID: "..tostring(newSound))
Called = false -- changing debounce here ←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←
wait(0.25)
end
--
stationStorage.station995.timeLengthEvent.OnServerEvent:Connect(function(player, length)
stationStorage.station995.timeLength.Value = tostring(length)
end)
stationStorage.station995.timePositionEvent.OnServerEvent:Connect(function(player, pos)
stationStorage.station995.timePosition.Value = tonumber(pos)
end)
--
while true do
local value = stationStorage.station995.timePosition.Value
if value == 0 and not Called then
Called = true
update955()
end
task.wait(0.1)
end
Oh sorry shoot i noticed an error i did. DONT set the debounce back to false. Thatll just run the function again. Sorry my bad. Just remove the and it should only call it one time. Again sorry my bad. An error on my end
local connection = nil
local function DoStuff()
end
connection = TimePosition:GetPropertyChangedSignal("Value"):Connect(function()
if TimePosition.Value == 0 then
connection:Disconnect()
connection = nil
DoStuff()
end
end)
local freq955 = game.ReplicatedStorage.radioStations.station995
freq955.timePosition.Changed:Connect(function(NewValue)
if NewValue == "0" then
update955()
else
print("not 0")
end
end)