I am making a plugin which requires a gui to be updated when a part or model moves. Detecting when a part moves is easy, just the basic :GetPropertyChangedSignal. However, for models, its much trickier.
I want to avoid RunService connections and loops as much as possible so the plugin has no impact on performance. Is there any way to find out of a model has moved with as little performance impact possible.
Yes, there are properties like “Origin Position” on models, but they cant be accessed by scripts and cannot have GetPropertyChangedSignal attached onto them.
1 Like
You may be able to pick a random part within the model and then detect it’s movement
2 Likes
How about trying to check when the position of the Models PrimaryPart has changed, if the model doesn’t have a primary part, then check if a random part in the model has change like what @SeargentAUS said
local model = game.Workspace.Model
model.PrimaryPart:GetPropertyChangedSignal("Position"):Connect(function()
print("Model Moved!")
end)
1 Like
@domboss37 Sorry for the bump on the topic, but I can’t seem to get this solution to work for me. I have created a model and set its PrimaryPart
to the part inside the model; I move the model and it doesn’t print anything from the script. Can anybody help? Thanks.
local model = script.Parent
model.PrimaryPart:GetPropertyChangedSignal("Position"):Connect(function()
print("Model Moved!")
end)
Are you moving the object via local script or a server script?
Likewise, are you trying to detect it from a server script or a local script
Nevermind. Just found out that: :GetPropertyChangedSignal("Position"):Connect(function()
can only be used, when it involves movement via localscripts or scripts and not if they are being physically moved:
Note that this event will not pass any arguments to a connected function, so the value of the changed property must be read directly within a script.
Hope this makes the solution listed clearer to others.