Help with making a part always looking at the player (there orientation changes to players)

im trying to make it so a humanoid is always looking at a player. when i try to it doesnt work.

heres the script:

game.Players.PlayerAdded:Connect(function(plr)
	while true do
		wait()
		script.Parent.Orientation = script.Parent.Orientation + plr["Origin Orientation"]
		end
end)

the script is a script inside the humanoid.

the error is Origin Orientation is not a valid member of Player "Players.SakDevRblx" - Server - Script:4

1 Like

Roblox actually has a function build into CFrame to do this, called CFrame.lookAt()

Here is the video I used to learn it:

To use this for a humanoid, you could use

player.Character.HumanoidRootPart.Position.Changed:Connect(function()
     --use CFrame.lookAt() on the part here
end)

so how would i write the full script (Sorry im still sort of confused where to put “Look at”)

in the video it says lookat a part. how would i look at the player?

This is probably going to have some bugs because I am not writing this on studio

player.Character.HumanoidRootPart.Position.Changed:Connect(function()
   script.Parent.CFrame.lookAt(script.Parent.Position, player.Character.HumanoidRootPart.Position)
end)

What this does is when a player moves, it fires an event that makes the part look at the HumanoidRootPart of the player. You would want to make this a local script so that it looks at each player. You might also want to make it so that if the player cannot see the part, then it does not run the script, to reduce lag issues.

i changed the script to this and im getting this error

script:

game.Players.PlayerAdded:Connect(function(Plr)
	while true do
wait()
		Plr.Character.HumanoidRootPart.Position.Changed:Connect(function()
			script.Parent.CFrame.lookAt(Plr.Character.HumanoidRootPart.CFrame)
		end)
	end
end)

error:

Workspace. .Script:3: attempt to index nil with ‘HumanoidRootPart’ - Server - Script:3

If it is a local script you can just do this to get the player

local Plr = game.Players.LocalPlayer.Character

new script:

 local Plr = game.Players.LocalPlayer.Character
while true do
		wait(0.1)
		Plr.Character.HumanoidRootPart.Position.Changed:Connect(function()
			script.Parent.CFrame.lookAt(Plr.Character.HumanoidRootPart.CFrame)
		end)
	end

nothing happens : no error. maybe its becuase im trying to move a model and a model doesnt have a Cframe?

CFrame.lookAt() takes two parameters. The first one is the part you want to move. The second one is where you want it to look.

For this to work with a model, you will need to get a part to act as the Root of the model. Weld all of the other parts to that Root. UnAnchor every part except for the Root part. Then put this script in the Root.


local Plr = game.Players.LocalPlayer.Character
while true do
		wait(0.1)
		Plr.Character.HumanoidRootPart.Position.Changed:Connect(function()
			script.Parent.CFrame.lookAt(script.Parent.Position, Plr.Character.HumanoidRootPart.Position)
		end)
	end

the humanoid has a built in rootpart (edit i put in humanoidrootpart but didnt work)

Unanchor the entire humanoid, then Anchor only the root part. Try replacing script.Parent.Position with script.Parent.CFrame, and replace Plr.Character.HumanoidRootPart.Position with Plr.Character.HumanoidRootPart.CFrame

the humanoid model is already like this it must be sript issue

(i tryed alll of it nothing changes)

I use a plugin to create humanoid characters. I know that the only way to change a Humanoid model’s position is by changing the CFrame of the base part. So try replacing the positions of the part’s with their CFrames.

local Plr = game.Players.LocalPlayer.Character

while true do

wait(0.01)

Plr.Character.HumanoidRootPart.Position.Changed:Connect(function()

script.Parent.CFrame.lookAt(script.Parent.CFrame, Plr.Character.HumanoidRootPart.CFrame)

end)

end

not working

by the way i put it in the humanoidrootpart

Try putting a print in the function to see if it is running.

i did and its not running. it didnt print it a single time

It looks like it is not registering that the players position is being changed. Print out your Plr variable to see if it prints out the right thing.

Another possible explanation is that the client cannot see changes in position. To fix this try to convert it to a normal script, not a Local one.
(You would have to use remote events to get the player’s character)

I just want to mention that HumanoidRootPart.Position.Changed is not a valid event

maybe its becuase when we called plr it errored but didnt send an error. ussually thats what happens for this kind of stuff

Is there a remote event to detect a change in position?