Activating an audio via 'while true do' without it stopping

Hey there, so my goal is to get the audio to play as well as light up a certain brick, however, the audio doesn’t play. Can someone please help me with this? Thanks!

while true do
if LeftFire.Value == true then
	LeftAudio:Play()
	L.Light.Material = "Neon"
end
if LeftFire.Value == false then
	LeftAudio:Stop()
	L.Light.Material = "Glass"
end
end

It’s not working because its in a while true loop constantly playing every fraction of a second, to fix it you would only play it once per change in value. Either way I’d recommend changing both to only fire once per change in value because there’s no need for it to be in a loop, your only changing a property and playing a sound.

2 Likes

You forgot to add a wait() inside your while loop.

as @SquidyCakez said you need to put your code into a changed function like this:

 LeftFire.Changed:Connect(function()
if LeftFire.Value == true then
	LeftAudio:Play()
	L.Light.Material = "Neon"
end

if LeftFire.Value == false then
	LeftAudio:Stop()
	L.Light.Material = "Glass"
    end
end)
1 Like

Thanks very much, it all worked plus it makes the code cleaner. I owe you one!

1 Like