Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do you run a function if a bool value changes?

When I press a button, a bool value changes. How do I make it run a function when the bool value changes? I want the function to activate when the bool value changes. Here's my script. Thanks.

local ChargeValue = script.Parent.Parent.Stats.Actions.Charge

local function ChargeAction()

	print("Value Changed")

end

ChargeValue.Changed:Connect(ChargeAction)

ChargeValue.Value = false	

3 comments

0

Use BoolValue.Change instead of changed

0

maybe the boolvalue is already at false, so there isnt any change

0

@JesseSong Could you elaborate please?

1 answer

First, check if the changed property is actually the Value, then run the function, and last thing is to make the value false.

ChargeValue:GetPropertyChangedSignal("Value"):Connect(function()
ChargeAction()
ChargeValue.Value = false
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.