Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Is there any way to detect when a models position moves?

Asked by 3 years ago
Edited 3 years ago

Please help me! ive tryed many ways including using the humanoidrootpart but it hasnt worked

game.ReplicatedStorage.Camera1.OnClientEvent:Connect(function()
    wait(4)
    local camera = workspace.CurrentCamera
    local TweenService = game:GetService("TweenService")
    camera.CameraType = Enum.CameraType.Scriptable
    camera.CFrame = workspace.Stage1.Camera1.CFrame

    workspace.Stage1.AttributeChanged:Connect(function() --Stage1 is the Dummy
        camera.CFrame = workspace.Stage1.Camera1.CFrame
        print("Changed")
    end)
end)

I have that code to make the camera redirect itself whenever the dummy moves but it doesent work

0
By Model i mean dummy like character TeaWithMee 76 — 3y

3 answers

Log in to vote
0
Answered by
NGC4637 602 Moderation Voter
3 years ago

There are two properties of the character's humanoid, namely WalkToPart and WalkToPosition. Perhaps you can do something with it?

or you can maybe just do Humanoid.StateChanged event.

0
I reposted code maybe that could help a little bit more, and i understand and ive tried that but it doesnt work TeaWithMee 76 — 3y
Ad
Log in to vote
0
Answered by
Hypoxla 125
3 years ago

You could use a changed event.

Example:

local HumanoidRootPart = --PATH TO PART

HumanoidRootPart:GetPropertyChangedSignal("Position"):Connect(function()
    -- do stuff when player moves
    end)
0
the humanoidrootpart doesnt seem to move with the dummy TeaWithMee 76 — 3y
Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

Hello,

To check when the model's position has changed, we use AttributeChanged, and the model's Primary Part

The Primary Part is the main part of a Model, meaning that when the Primary Part's position changes, the Model's position changes.

The AttributeChanged event will tell us if a property of a model changes AND which specific property has been changed.

First, verify that your model contains a Primary Part by clicking on it in the explorer window, looking at the property window and verifying that the PrimaryPart property is not a nil value.

Here's how I'd implement a system that detects when a model changes position:

local model = --PATH TO MODEL
local primary = model.PrimaryPart -- MODEL'S PRIMARY PART

local function attributeChanged(attributeName)
    print(attributeName, “changed”)
end

primary.AttributeChanged:Connect(function(attribute)

    if attribute == "Position" or "Orientation" then --CHECK TO MAKE SURE WE'RE UPDATING CAMERA POSITION BECAUSE OF A POSITION/ROTATION CHANGE
        camera.CFrame = primary.CFrame
    end

end)


Please note that your question has no information about the errors you're experiencing, so it is difficult to understand your issue.

I hope this helped!

Cheers, Ninjamanchase

Answer this question