Im trying to make the character face the ehrp (character must be able to move while facing ehrp)

But i get the error Attempt to call a nil value, ON line 34

local LookAt = Player.Parent.Torso.CFrame:PointToWorldSpace(Vector3.new(0,0, -3)):lerp(eHRP.Torso.Position, .1)
        Player.Parent.Torso.CFrame = CFrame.LookAt(Player.Parent.Torso.Position, LookAt, Player.Parent.Torso.CFrame.UpVector)

7 Likes

it is CFrame.lookAt not CFrame.LookAt

3 Likes


new problem my character cant move now?

3 Likes

I need more of the script to understand what is wrong

4 Likes

        local Player = game.Players.EekPlayz09.Character.Head
        local eHRP

        for i, v in pairs(game.Players:GetChildren()) do
            if v.Name ~= Player.Parent.Name then
                eHRP = v.Character
            end
        end

        local Hight = math.abs((eHRP["Left Leg"].Position.Y - eHRP.Head.Position.Y))

        local raycastParams = RaycastParams.new()
        raycastParams.FilterDescendantsInstances = {eHRP.Parent}
        raycastParams.FilterType = Enum.RaycastFilterType.Exclude

        local raycastResult = workspace:Raycast(eHRP.Head.Position, Vector3.new(0, -(Hight* 2), 0), raycastParams)


        local Distance

        if raycastResult then
            Distance = (game.Players.EekPlayz09.Character.Head.Position - eHRP.Head.Position).magnitude
        else
            Distance = (game.Players.EekPlayz09.Character.Head.Position - eHRP["Left Leg"].Position).magnitude
        end


        local LookAt = Player.Parent.Torso.CFrame:PointToWorldSpace(Vector3.new(0,0, -3)):lerp(eHRP.Torso.Position, .1)
        Player.Parent.Torso.CFrame = CFrame.lookAt(Player.Parent.Torso.Position, LookAt, Player.Parent.Torso.CFrame.UpVector)

        print(Distance)

        if Distance < 25 then

            spawn(function()
                if Distance < 23 then
                    Player.Parent.Torso.Anchored = true
                    wait(0.2)
                    Player.Parent.Torso.Anchored = false
                    Player.Parent.Humanoid:ChangeState(Jump)
                end
            end)
            


            local Force = Instance.new("BodyVelocity", eHRP.HumanoidRootPart)
            Force.MaxForce = Vector3.new(0.5,0.3,0.5) * math.huge
            local Direction = (eHRP.HumanoidRootPart.CFrame.Position - game.Players.EekPlayz09.Character.HumanoidRootPart.CFrame.Position).Unit
            Force.Velocity = Vector3.new(Direction.X, 0.4, Direction.Z) * 20
            game.Debris:AddItem(Force, .44)
								
            local LoadedAnim = game.Players.EekPlayz09.Character.Humanoid:LoadAnimation(game.StarterPack.Sword.Handle.LocalScript.AnimationR15)
            LoadedAnim:Play()
								
								
								
            local SelectionBox = Instance.new("SelectionBox")
            SelectionBox.Parent = eHRP
            SelectionBox.Adornee = eHRP
            SelectionBox.Color3 = Color3.new(255, 0, 0)
            game.Debris:AddItem(SelectionBox, 0.4)
            wait(0.5)
2 Likes

I am sorry I am unable to help

2 Likes

If they are unable to move, I would recommend just using Align Orientation to fix your problem. Align orientation uses CFrames, however, it doesnt stunt the players movement… This could be helpful.

4 Likes

I did this

 local model = Player.Parent.Torso
        local reference = eHRP.Torso


        local TweenService = game:GetService("TweenService")
        local tweeninfo = TweenInfo.new(.1, Enum.EasingStyle.Quad, Enum.EasingDirection.In, -1, true, .5)
        local properties = {Position = reference.Position + Vector3.new(0,10,0)}


        local tween = TweenService:Create(reference, tweeninfo, properties)

        tween:Play()

and its not working?

2 Likes

Align orientation uses CFrames.

3 Likes

can you give an example on how you would use it

2 Likes

local cframe = CFrame.lookAt(at, lookAt)
align_orientation.CFrame = cframe

3 Likes

attempt to index nil with cframe

        local model = Player.Parent.Torso
        local reference = eHRP.Torso


        local cframe = CFrame.lookAt(model.Position, reference.Position)
        align_orientation.CFrame = cframe

1 Like

assuming variable Player is a Player object

local playerPos = Player.Character:GetPivot().Position -- Get current character CFrame.Position
local ehrp = eHRP.Torso

Player.Character:PivotTo(CFrame.lookAt(playerPos, ehrp.Position)) -- Use CFrame.lookAt to orient the character to face ehrp
2 Likes

its on the sever, and it flung me to the side of the map

local model = Player.Parent.Torso
        local reference = eHRP.Torso

        model.parent:PivotTo(CFrame.lookAt(model.position, reference.position))

1 Like

you need to use :GetPivot().Position on the character model for more accuracy

1 Like

Pretty sure if you force set the cframe of players it will almost 100% fling them.

1 Like

“attempt to index nil with cframe”, no? that sounds like its coming from this part:
align_orientation.CFrame = cframe

Are you sure align_orientation is assigned inside of the players torso?

1 Like

I did a test myself and it actually worked, but maybe the reason he getting flinged is that his character isnt massless?

2 Likes

how do i assign it into a torso?

2 Likes

Unable to create an instance of “align_oriantation”

2 Likes