Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

1 comment

0

By Model i mean dummy like character

3 answers

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.

1 comment

0

I reposted code maybe that could help a little bit more, and i understand and ive tried that but it doesnt work

You could use a changed event.

Example:

local HumanoidRootPart = --PATH TO PART

HumanoidRootPart:GetPropertyChangedSignal("Position"):Connect(function()
	-- do stuff when player moves
	end)

1 comment

0

the humanoidrootpart doesnt seem to move with the dummy

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

This discussion is preserved as it was. New answers, comments, and votes are closed.