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

Why doesn't my script detect BoolValue's change?

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

2 comments

0

Extra information. The Knife is in ReplicatedStorage

0

Nevermind! I found what I did wrong and fixed it! Thank you @Feahren and @Elixcore for taking their time to help me!

3 answers

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)

5 comments

0

Hmm...

0

I tried my code with that code, still not functioning. The message does not appear

0

Is the program doing what you intended it to do?

0

Mhm, the BoolValue gets ticked, but this script doesn't function

0

I assume this is because the Script is attempting to run under ReplicatedStorage? If so, it won’t execute there; it must be relocated to run in a place where it can do so respectively. If it’s a child of a Tool, I suggest migrating said object to the Backpack, and formatting the code into a LocalScript. If not, have the program run as a ServerScript under workspace or ServerScriptService

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)

5 comments

0

Unfortunately I won't even receive the printed message

0

that means the script is not starting, make sure the script is located somewhere where it would work and also there is no loop before it, or something that will stop it from executing

0

The script is inside of Knife, which is inside of ReplicatedStorage

0

scripts inside replicatedstorage do not execute, it is just a place for storage, if you want the script to execute you need to bring it out of there.

0

It gets brought to Workspace by another script

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.

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