Why this event isnt working?

Hi, my question is simple, why this isnt working

workspace.ship.PrimaryPart.Changed:Connect(function ()
print("change")
end)

I want to fire this, when primary part cframe change

1 Like

Hello yet again (lol)
You can use :GetPropertyChangedSignal to connect on a certain property changing, here’s how:

workspace.ship.PrimaryPart:GetPropertyChangedSignal("CFrame"):Connect(function()
    print("The CFrame has changed!")
end)
1 Like

And why isnt my code working??

There could be multiple reasons why, my only hypothesis is that it’s being fired too many times for it to handle (yes that can happen).

1 Like

not working…

I tested this in studio and it worked for me, are you certain that there’s a PrimaryPart?

ya

main is a Model, you’ll want to change it to a singular part.

1 Like

no, main is part (in the same named model)

The event .Changed is fired only when a property of the “selected instance” changed.
It’s not working maybe because your instance (here main) not changing.
You also can’t use the .Changed event with a model for detect when the PrimaryPart change.

So you should just rename the PrimaryPart (and select PrimaryPart not by a property) :

workspace.ship.[Name Of The Part].Changed:Connect(function()
print(“change”)
end)

Make sure that you change model’s position with funciton SetPrimaryPartCFrame. This might be also useful if you are moving model from one distance to the other distance.
I hope this helps. :herb:

Part:GetPropertyChangedSignal()

behaves just like a .Changed event, except you can modify it to connect to a function based on a certain quality of the object changing.

for example

If you insert a script with this code :
–We will suppose you have set a primary part for the whole model
, so then you can detect changes in the property of that specific part.

local part = script.Parent--primary part of the model

       part:GetPropertyChangedSignal("CFrame"):Connect(rotated)
	
	function rotated()
	    print("the position of the part is " .. part.CFrame.Position)
	       end
	
	print(part:GetPropertyChangedSignal(CFrame) == part:GetPropertyChangedSignal(CFrame))

i tried this

workspace.ship.main.mainPart:GetPropertyChangedSignal("CFrame"):Connect()

but nothing

Maybe because nothing change. Try again with a script that change the CFrame

1 Like

I tried using

workspace.ship.PrimaryPart.CFrame=workspace.ship.PrimaryPart.CFrame+Vector3.new(0,100,0)

but also nothing

I dont know, but you are attempting to add a Vector3 and a CFrame. I vaguely remember that technically being ok, but try this:

workspace.ship.PrimaryPart.CFrame=workspace.ship.PrimaryPart.CFrame+CFrame.new(Vector3.new(0,100,0))

Just, for be sure, try this (I don’t know if it’s working, I am very bad with CFrame) :
workspace.ship.PrimaryPart.CFrame=CFrame.new(Vector3.new(0,100,0))

ok, but anyway, the cframe change (it go 100 up), but the event wont fire

Send a screenshot of what it looks like in the script, with the explorer open, showing where your script is, and screenshot the whole page.

It’s probably that the Changed event and the RBXScriptSignal returned from GetPropertyChangedSignal will not fire if there’s a change in position and cframe

You can use RunService.Stepped:Connect() to check to see if there are changes in its position

1 Like