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