:GetPropertyChangedSignal() is not firing sometimes

Hi, I don’t think much context is needed for my situation. I have a boolean value that I am changing on the client, but :GetPropertyChangedSignal() is not firing when I first change it. I have seen things about boolValues not replicating to the server, but it doesn’t make sense because the function still fires when I change the boolValue in another part of my code. I’ve tried using boolValue.Changed event instead but it also made no difference. I have not yet tried firing remote events because it wouldn’t quite fit what I’m trying to do.

Here’s my script:

local function movingPartTouched()
	if character:FindFirstChild("Humanoid") then
		firstTouched.Value = true
		connection:Disconnect()

		AnimateScript.run.RunAnim.AnimationId = RunAnimId
		AnimateScript.idle.Animation1.AnimationId = IdleAnimationId
		AnimateScript.walk.WalkAnim.AnimationId = WalkAnimationId
		humanoid.JumpPower = 0
		humanoid.WalkSpeed = 1
		local firstTween = TweenService:Create(movingPart, startTweenInfo, {Position = movingPart.Position + Vector3.new(0,-2,0)})
		firstTween:Play()
		firstTween.Completed:Wait()
		print("Tween completed")        --prints
		tweenCompleted = true
		jumping.Value = false --jumping.Value prints as false, but does not fire jumping:GetPropertySignalChanged()

		
		inputConnection = UserInputService.JumpRequest:Connect(function()
			print("input") --prints
			jumping.Value = true --fires jumping:GetPropertyChangedSignal()
			while task.wait() and tweenCompleted do				
				if not jumping.Value then return end
				
				local tweenUpGoals = {Position = movingPart.Position + Vector3.new(0,.25,0)}
				local tweenUp = TweenService:Create(movingPart, tweenInfo, tweenUpGoals)
				if movingPart.Position.Y >= 11 then
					print("player escaped the quicksand")
					humanoid.WalkSpeed = defaultWalkSpeed
					humanoid.JumpPower = defaultJumpPower
					AnimateScript.run.RunAnim.AnimationId = defaultRun
					AnimateScript.idle.Animation1.AnimationId = defaultIdle
					AnimateScript.walk.WalkAnim.AnimationId = defaultRun
					movingPart.Position = Vector3.new(movingPart.Position.X, 10.317, movingPart.Position.Z)
					firstTouched.Value = false
					return
				end
				
				tweenUp:Play()
				print("value of jumping before tween is completed: " ..tostring(jumping.Value))
				tweenUp.Completed:Wait()
				print("tween completed")
				upTweenCompleted = true
				jumping.Value = false --this fires  jumping:GetPropertyChangedSignal(), but changing it at the start of the script did not
				print("value of jumping after tween: "..tostring(jumping.Value))
			end
		end)
		jumping:GetPropertyChangedSignal("Value"):Connect(function()
			print("jump value changed to: "..tostring(jumping.Value)) --prints when changed inside the .JumpRequest but does not print when jumping is changed at the start of the script.
			while task.wait() and tweenCompleted and not jumping.Value do
				if jumping.Value then return end
				local tweenDownGoals = {Position = movingPart.Position + Vector3.new(0, -.5, 0)}
				local tweenDown = TweenService:Create(movingPart, tweenInfo, tweenDownGoals)
				tweenDown:Play()
				tweenDown.Completed:Wait()
			end
			
		end)
	end
end
connection = movingPart.Touched:Connect(movingPartTouched)

firstTouched:GetPropertyChangedSignal("Value"):Connect(function()
	print("entered") --prints
	if firstTouched.Value == false then
		print("waiting for part to be touched")
		jumping.Value = true
		inputConnection:Disconnect()
		
		connection = movingPart.Touched:Connect(movingPartTouched)
	end
end)


I’ve been trying to debug but it doesn’t make any sense how the firstTouch boolValue I’m using fires everytime, while my jumping boolValue only fires for some parts. Any responses would be greatly appreciated.

1 Like

Changing a value on the client does not replicate to the server

Did you read my post… How come it still fires sometimes?

If you’re only changing the value on the client, those changes shouldn’t be seen or detected by the server

Are you sure it’s being detected on the server? (Like a screenshot or something?)


@AborayStudios that’s not helpful considering there could be a different issue here

The boolvalue is not being changed or detected by the server. But :GetPropertyChangedSignal() is still firing sometimes

The issue here:

Occurs because your actual detector for the BoolValue changing is defined after you change the value to false:

jumping.Value = false
-- ...
jumping:GetPropertyChangedSignal("Value"):Connect(function()  -- since this is defined afterwards, the script hadn't gotten to it yet, and thus, it won't first when the value is changed initially
	print("jump value changed to: "..tostring(jumping.Value))
	while task.wait() and tweenCompleted and not jumping.Value do
	if jumping.Value then return end
		local tweenDownGoals = {Position = movingPart.Position + Vector3.new(0, -.5, 0)}
		local tweenDown = TweenService:Create(movingPart, tweenInfo, tweenDownGoals)
		tweenDown:Play()
		tweenDown.Completed:Wait()
	end
			
end)

Likewise for the JumpRequest signal; the GetPropertyChangedSignal is connected and running by the time the JumpRequest signal is executed, which allows it to fire the signal.

It’s also the same reason why the firstTouched event fires; it’s connected and running by the time the movingPart.Touched event is fired.

Basically, the issue with your code was race conditions

Ohh I didn’t even know this problem existed, thank you for the response. So would I fix this by changing the value further down the code or adding a wait or something? I’ve never dealt with something like this yet

Yes:

-- ...
jumping:GetPropertyChangedSignal("Value"):Connect(function()  -- since this is defined afterwards, the script hadn't gotten to it yet, and thus, it won't first when the value is changed initially
	print("jump value changed to: "..tostring(jumping.Value))
	while task.wait() and tweenCompleted and not jumping.Value do
	if jumping.Value then return end
		local tweenDownGoals = {Position = movingPart.Position + Vector3.new(0, -.5, 0)}
		local tweenDown = TweenService:Create(movingPart, tweenInfo, tweenDownGoals)
		tweenDown:Play()
		tweenDown.Completed:Wait()
	end
			
end)

-- change it here
jumping.Value = false

I just tried it and it worked. Thank you!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.