Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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)

4 comments

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)

0

CFrame.LookVector returns a vector3 not a CFrame. You should learn about them on the developer wiki.

0

oh yeah that's right, i'll change that real quick

0

i forgot to test it

1 answer

✓ Accepted answer

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"

This discussion is preserved as it was. New answers, comments, and votes are closed.