This might be a bit difficult to explain but I am making a script that works when you have 0 or under “Vision Time” by covering your screen with a Frame, and when it is over 0, the Frame turns Invisible. I used GetPropertyChangedSignal but it keeps playing the sound when it is over 0 Vision Time. Does anyone have an idea how to make it only play once after it is over 0?
local player = script.Parent.Parent.Parent.Parent
local leaderstats = player:WaitForChild("leaderstats"):WaitForChild("Vision Time")
local frame = script.Parent
local sound = script.Parent.Parent.SwitchSound
local function updateScreen()
if leaderstats then
local value = leaderstats.Value
if value <= 0 then
frame.Visible = true
sound:Play()
else
frame.Visible = true
sound:Play()
end
end
end
leaderstats:GetPropertyChangedSignal("Value"):Connect(updateScreen)
local player = script.Parent.Parent.Parent.Parent
local leaderstats = player:WaitForChild("leaderstats"):WaitForChild("Vision Time")
local frame = script.Parent
local sound = script.Parent.Parent.SwitchSound
local function updateScreen()
if leaderstats then
local value = leaderstats.Value
if value <= 0 then
frame.Visible = true
sound:Play()
else
frame.Visible = false
sound:Stop()
end
end
end
leaderstats:GetPropertyChangedSignal("Value"):Connect(updateScreen)
local player = script.Parent.Parent.Parent.Parent
local leaderstats = player:WaitForChild("leaderstats"):WaitForChild("Vision Time")
local frame = script.Parent.Parent
local sound = script.Parent.Parent.SwitchSound
local toggled = false
local function updateScreen()
if leaderstats then
local value = leaderstats.Value
if value <= 0 then
frame.Enabled = true
sound:Play()
toggled = true
else
if toggled == true then
frame.Enabled = true
sound:Play()
toggled = false
end
end
end
end
leaderstats:GetPropertyChangedSignal("Value"):Connect(updateScreen)