BoolValue.Changed not working

Dest.touching.Changed:Connect(function(newValue)

   print(newValue)

   if newValue then
     --code
   end
end)

It’s not printing print(newValue) I also tried printing other stuff but it’s not printing anything.
I am not getting any errors.

BoolValue changing code:

function npc(NpcTouched)
	if NpcTouched.Parent:FindFirstChild("NPC") then
		script.Parent.touching.Value = true
	end
end

script.Parent.Touched:Connect(npc)

The BoolValue changes.

This is where the BoolValue is in the Explorer:
Ekran Alıntısı
The DestTwo is in Workspace.

2 Likes

Do Dest.Value.Changed:Connect(function(newValue)
end)

That gives an error. I tried that before and the BoolValue | Documentation - Roblox Creator Hub made it like I made it.

Where are you changing the value of the BoolValue, in a Script or a LocalScript?
I’m fairly sure a ValueObject’s value doesn’t replicate, so if you change the value on the client, it won’t appear changed on the server.

I am changing it in a serverscript. Both codes are in a serverscript.

I am pretty sure .Changed() returns the property, not the value.
Try:

Dest.touching:GetPropertyChangedSignal("Value"):Connect(function(val)
    print(val)

    if val then
        --code
    end
end)

Instead of doing like for example,

part.Name.Changed:connect...

Do this:

part.Changed:connect(function(prop)
if prop == "Name" then
--code
end
end)

Sorry if I made errors, I’m on mobile.

My experiences with Changed showed me that first one never works, use the second method.

1 Like

This also doesn’t work I am not getting any errors

Then you’re doing something wrong, I’ve just experimented and it didn’t fail. Can you show your explorer?

Ok, I edited my post. (30 char)

Seems like there may be an issue with the initial changing of the value. Could you try this script and show the output here?

2 Likes

Ekran Alıntısı2

Nevermind, I was wrong. :GetPropertyChangedSignal() returns nothing. Your earlier code seems good. It worked for me.
My test script:

spawn(function()
	while wait(5) do
		script.Parent.Value = not script.Parent.Value
	end
end)

script.Parent.Changed:Connect(function(val)
	print(val)
end)

My explorer:

image

My output:

image

.Changed doesn’t work for me either sometimes, try using GetPropertyChangedSignal() instead. That usually fixes it for me.

boolValue:GetPropertyChangedSignal("Value"):Connect(function() 
    print("The bool's value changed to "..boolValue.Value)
end)