How to check if a cframe value changed

I can’t come up with a solution to this, so basically, we have a CFrame,

When the caller passes an argument that is a cframe, I need to listen to some sort of change event.

local ListenForCall = function(cf, f)

cf is the cframe, and f is the function to fire whenever the cf changes

how

--For this one, you'll need a `CFrameValue`.
Workspace.CFrameValue.Changed:Connect(function(NewValue)
    print(NewValue)
end)
 
Workspace.CFrameValue.Value = CFrame.new(0, 20, 0)
1 Like
local Game = game
local Workspace = workspace
local RunService = Game:GetService("RunService")
local Part = Workspace.Part
local CFrameValue = Part.CFrameValue

local function OnChanged(Value)
	print(Value)
end

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

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

You can constantly update a ‘CFrameValue’ object and use its ‘Changed’ event/signal.
https://developer.roblox.com/en-us/api-reference/event/CFrameValue/Changed

1 Like

Its a cframe, theres no parts, this wont work, I said u assign a cframe, a literal one

the function takes in a cframe, no parts, read more carefully then reply, it can be any cframe, a part’s cframe, a actual cframe like CFrame.new(1,1,1) there’s no parts

Theres no parts you can assign to the function, it takes a CFrame and a function

Now when that cframe changes we call on the function

read more carefully then reply

Learn to implement solutions that might require a refactoring of your code.

1 Like

It is possible I misunderstood your question, but it sounds like you have something which will receive a CFrame, and not a property change. If this is the case you could call the function f() whenever the function ListenForCall() is fired.

Otherwise I would create a BindableEvent | Roblox Creator Documentation instead of passing a function through. You would then call :Fire() on the bindable even once the function is called and do bindableEvent.Event:Connect(f) somewhere else in the code.

-- Example w/o bindable event:
function ListenForCall(cf: CFrame, f: Function)
	f()
	...
end

-- Example with bindable event:
local cframeAssigned: BindableEvent = Instance.new("BindableEvent")

function ListenForCall(cf: CFrame)
	cframeAssigned:Fire()
	...
end)

cframeAssigned.Event:Connect(f)