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
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
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
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
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
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)