Hello! I have made a Script
, which detects if a BoolValue has changed and then checks if it's ticked. Though it does not work, obviously... The BoolValue does get ticked and unticked, but is not detected by this script.
Knife = script.Parent KnifeZone = game.ReplicatedStorage.KnifeZone SwingCheck = Knife.Swinging if SwingCheck.Value:Changed() then print("BoolValue changed!") if SwingCheck.Value == true then KZclone = KnifeZone:Clone() KZclone.Parent = game.Workspace KZclone.Position = Knife.Knife.Position KZclone.Orientation = Knife.Knife.Orientation wait(0.5) KZclone:Destroy() end end
You’re attempting to reference a method of Value
which doesn’t exist. Although there is a method of Instance
that does listen for change events, it’s not titled Changed()
, but in fact, GetPropertyChangedSignal()
. Another similar signal is also the .Changed()
event; although applicable in this situation, it only can listen for Values, whereas the separate method can fire for all modified properties—therefore recognized as a stronger practice.
SwingCheck:GetPropertyChangedSignal("Value"):Connect(function() print("Value Changed!") if SwingCheck then --// code Lines 8-13 end end)
Hey, LordTechet. What you are currently doing is trying to use an Event, as a Function.
.Changed cannot be used like you would use something like :Destroy().
It is a special event, also known as RBXScriptSignal.
They function by being combined with 2 different functions, .Changed:Wait(), or Changed:Connect(function).
In this case what you want to do is this:
Change this to an event.
if SwingCheck.Value:Changed() then
Like so:
SwingCheck.Value.Changed:Connect(function() --code end)
Your finished code should look something similar to:
Knife = script.Parent KnifeZone = game.ReplicatedStorage.KnifeZone SwingCheck = Knife.Swinging SwingCheck.Value.Changed:Connect(function() print("BoolValue changed!") if SwingCheck.Value == true then KZclone = KnifeZone:Clone() KZclone.Parent = game.Workspace KZclone.Position = Knife.Knife.Position KZclone.Orientation = Knife.Knife.Orientation wait(0.5) KZclone:Destroy() end end)
Is the boolvalue being changed by a localscript? If so, the server won't recognize a change in it. To get around this have the local script fire a remoteevent to change the value.