Why does the while loop work, but not getpropertychangedsignal?

while wait() do
	if math.abs(script.Parent.AssemblyLinearVelocity.Y) >= speed or math.abs(script.Parent.AssemblyLinearVelocity.X) >= speed or math.abs(script.Parent.AssemblyLinearVelocity.Z) >= speed then

		print("AAAAAAAAAAAAAAAAAAAAAAAAAAAH")

	end
end

That works.

script.Parent:GetPropertyChangedSignal("AssemblyLinearVelocity"):Connect(function()
	if math.abs(script.Parent.AssemblyLinearVelocity.Y) >= speed or math.abs(script.Parent.AssemblyLinearVelocity.X) >= speed or math.abs(script.Parent.AssemblyLinearVelocity.Z) >= speed then

		print("AAAAAAAAAAAAAAAAAAAAAAAAAAAH")

	end
end)

This does not.
Why?

Is the Velocity changing in the first place?

If I recall, Property changes to physics will not apply to event changes such as .Changed & GetPropertyChangedSignal()

Although I do believe you can use a Vector3Value instead to workaround this:

local Vec3Val = workspace:WaitForChild("Vector3Value")

Vec3Val.Changed:Connect(function(Vector3)
    if math.abs(Vector3.X) >= speed or math.abs(Vector3.Y) >= speed or math.abs(Vector3.Z) >= speed then
        print("H")
    end
end)

well the top script working would imply that it is or else the velocity would never except “speed”
but yes its changing fairly certain

so what youre saying is have a vector3value that is constantly being updated to the velocity of the part?
and then just used .changed for the value?

in order to constantly update the value as the velocity of the part, wouldnt that also require a while loop, rendering it almost no different than my original script with the while loop?

If you put a print inside the GetPropertyChangedSignal but outside the if, does it print anything?

That seems like the alternative workaround, but that’s also kinda where our development gets strict

.Changed & GetPropertyChangedSignal() Events can’t detect physics related properties when they get updated each time, mostly due to how often it would fire

Or you could use a loop, and use RunService for something like this:

local RS = game:GetService("RunService")
local Vec3 = workspace:WaitForChild("Vector3Value")
local Part = workspace:WaitForChild("Part") -- Reference Part here
local Speed = 0 -- Speed here

RS.Heartbeat:Connect(function()
	Vec3.Value = Part.Velocity
	
	local XCheck = math.abs(Vec3.X >= Speed)
	local YCheck = math.abs(Vec3.Y >= Speed)
	local ZCheck = math.abs(Vec3.Z >= Speed)
	
	if XCheck or YCheck or ZCheck then
		print("A")
	end
end)
1 Like

That’d work.

local Game = game
local Workspace = workspace
local RunService = Game:GetService("RunService")
local Part = Workspace.Part --Don't need 'WaitForChild' if this is a server script.
local CFrameValue = Part.CFrameValue

local function OnChanged(Value)
	--Do code.
end

local function OnHeartbeat()
	CFrameValue.Value = Part.CFrame
end

CFrameValue.Changed:Connect(OnChanged)
RunService.Heartbeat:Connect(OnHeartbeat)

The Changed event/signal doesn’t fire unless the value is changed.

They can. But the engine will not trigger thede events for performance reasons.