Boolean value script not working

If you are running stuff on the client(the player) it should always be ran from a LocalScript instead of a script. Scrips should only ever be used for server sided things(e.g: in ServerScriptService)


I think the reason why your script isn’t working is because the while loop doesn’t resume running when you change the enabled value back to true. Conditional loops only run when the value is true to the value you are checking in the loop and when the value changes the loop wont run again.

You should also try and avoid using loops in your code because of the drawbacks they bring. Instead you should always use events if there is an event for what you are trying to do. For example if you want to check if a value has changed, instead of using a infinite loop you should use the changed or GetPropertyChangedSignal events. This community tutorial may be of interest to you as it touched on using events instead of loops:

I am unsure exactly what you are trying to achieve with your code so the code below may not be right for you use case. Assuming you want the panic sound to play whenever the panic value changes to true you could use this code below:

local Panic = workspace.Effects.Panic

Panic:GetPropertyChangedSignal("Value"):Connect(function() -- Fires whenever the panic value changes
	if Panic.Value == true then
		script.panic:Play()
	end
end)

The GetPropertyChangedSignal in the code above will fire each time the panic value in workspace changes. Then the value will be check to see if it is actually true and if it is the panic sound will play.

3 Likes