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

How can I detect the CFrame.LookVector "position"?

Asked by 2 years ago

im trying to make a directional rapier sword, and i have no idea why this is considered an error, if i change it to only 0.1 instead of 0.1, 0.1, 0.1 it gives out an error called Players.realTongoKong.Backpack.Rapier.Script:8: attempt to index nil with 'Character' and i get an error like this Players.realTongoKong.Backpack.Rapier.Script:14: Expected 'then' when parsing if statement, got ',' if i use 0.1, 0.1, 0.1

do i need to change the values in some way or is it something else?

really sorry if this is a silly question im still new to scripting n all that stuff

full script:

script.Parent.Activated:Connect(function()

    local swingRightAnimation = script.Parent.Animations.SwingRight
    local stabAnimation = script.Parent.Animations.Stab
    local humanoid = script.Parent.Parent.Humanoid

    local player = game.Players:GetPlayerFromCharacter(script.Parent)
    local Character = player.Character or player.CharacterAdded:Wait()
    local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")


    local swingRightAnimationTrack = humanoid:LoadAnimation(swingRightAnimation)
    local stabAnimationTrack = humanoid:LoadAnimation(stabAnimation)
    if CFrame.LookVector < 0.1, 0.1, 0.1 then swingRightAnimationTrack:Play()
    end

end)
0
@Mathilinium made a bit of a mistake, so on his code on line 12 change the CFrane,new(0.1, 0.1, 0.1) to Vector3.new(0.1, 0.1, 0.1) MarkedTomato 810 — 2y
0
CFrame.LookVector returns a vector3 not a CFrame. You should learn about them on the developer wiki. MarkedTomato 810 — 2y
0
oh yeah that's right, i'll change that real quick Mathilinium 112 — 2y
0
i forgot to test it Mathilinium 112 — 2y

1 answer

Log in to vote
0
Answered by 2 years ago
Edited 2 years ago

Change your script to this

script.Parent.Activated:Connect(function()
    local swingRightAnimation = script.Parent.Animations.SwingRight
    local stabAnimation = script.Parent.Animations.Stab
    local humanoid = script.Parent.Parent.Humanoid

    local player = game.Players.LocalPlayer
    local Character = player.Character or player.CharacterAdded:Wait()
    local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")

    local swingRightAnimationTrack = humanoid:LoadAnimation(swingRightAnimation)
    local stabAnimationTrack = humanoid:LoadAnimation(stabAnimation)
    if HumanoidRootPart.CFrame.LookVector < Vector3.new(0.1, 0.1, 0.1) then
        swingRightAnimationTrack:Play()
    end
end)

I didn't know which body part's CFrame you wanted to check, so if the HumanoidRootPart isn't the right one, just change "HumanoidRootPart.CFrame.LookVector" to "Body Part.CFrame.LookVector"

Ad

Answer this question