Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by 4 years ago

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   
0
Use BoolValue.Change instead of changed JesseSong 3916 — 4y
0
maybe the boolvalue is already at false, so there isnt any change TheRealPotatoChips 793 — 4y
0
@JesseSong Could you elaborate please? VexTrexYT 28 — 4y

1 answer

Log in to vote
1
Answered by 4 years ago

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)
Ad

Answer this question