Problem with changed function

This is not working correctly and IDK why, so basically, in server, im changing boolvalue value or “InSquad”

Player["Status"]:FindFirstChild("InSquad"):GetPropertyChangedSignal("Value"):Connect(function(value)
	print("hi")
	if value == true then
		script.Parent.OnSquad:TweenPosition(UDim2.new(0,0,0,0), "Out", "Quad", 1, true)
	elseif value == false then
		script.Parent.OnSquad:TweenPosition(UDim2.new(-1,0,0,0), "Out", "Quad", 1, true)
	end
end)	

It’s printing “hi” but not changing position of OnSquad, any idea?

When using GetPropertyChangedSignal nothing is passed to the function. I would suggest you use Changed if it’s a value object like IntValue, NumberValue, etc… since the Changed event behaves differently for those instances compared to something like a part. When Changed fires on any of those, the new value is passed to the function unlike with other instances where the property changed is passed. In conclusion, you can either reference the value inside GetPropertyChangedSignal via InSquad.Value or use Changed and get the value passed to your function as an argument.

2 Likes

Maybe try this

Player["Status"]:FindFirstChild("InSquad"):GetPropertyChangedSignal("Value"):Connect(function(value)
	print("hi")
	if value then
        print('there is a value')
		script.Parent.OnSquad:TweenPosition(UDim2.new(0,0,0,0), "Out", "Quad", 1, true)
	else
        print('no value here')
		script.Parent.OnSquad:TweenPosition(UDim2.new(-1,0,0,0), "Out", "Quad", 1, true)
	end
end)

This doesn’t solve the issue, this just creates more confusion. Your code doesn’t work for the same reason OP’s code does not work.

@soutenu has the correct solution however

1 Like

Idk but see if this works:

Player["Status"]:FindFirstChild("InSquad").Changed:Connect(function()
	print("hi")
	local value = Player["Status"]:FindFirstChild("InSquad").Value
	if value == true then
		script.Parent.OnSquad:TweenPosition(UDim2.new(0,0,0,0), "Out", "Quad", 1, true)
	elseif value == false then
		script.Parent.OnSquad:TweenPosition(UDim2.new(-1,0,0,0), "Out", "Quad", 1, true)
	end
end)

Changed does pass in a new value while GetPropertyChangedSignal does not.
Also, why are you using FindFirstChild and also not just storing the InSquad value somewhere…?