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

attempt to index nil with 'aimSmooth'?

DISCLAIMER: Code of Xeradev on YT!

I´m currently working on an FPS with the help of the tutorials of the YT Channel Xeradev. When I added sounds, I got an error. "Players.LumpiMagDich.PlayerScripts.Framework - Client:112: attempt to index nil with 'aimSmooth'". The lines I wrote, edited have nothing to do with the line the error gives me, wich I made days ago, and never had problems with. checked if i did something wrong, but there is nothing I found.already red it means that it is indefinined, but i dont know where my problem is.

if isAiming and framework.viewmodel ~=nil and framework.module.canAim then
		local offset = framework.viewmodel.AimPart.CFrame:ToObjectSpace(framework.viewmodel.PrimaryPart.CFrame)
		aimCF = aimCF:Lerp(offset, framework.module.aimSmooth)
		currentSwayAMT = aimSwayAMT
	else
		local offset = CFrame.new()
		aimCF = aimCF:Lerp(offset, framework.module.aimSmooth) <- this is the error line
		currentSwayAMT = swayAMT
	end
end)

how do i fix it? all i red under the video was to change from r6 to r15, which i did to my character, but i really dont know what to do. If the problem is rlly dum, i'm sorry, started with Lua only a week ago, so i need everything to help me. thanks the code I recently added:

if viewmodelFolder:FindFirstChild(Item) then
			framework.viewmodel = viewmodelFolder:FindFirstChild(Item):Clone()
			framework.viewmodel.Parent = camera
			
			fireAnim = Instance.new("Animation")
			fireAnim.Parent = framework.viewmodel
			fireAnim.Name = "Fire"
			fireAnim.AnimationId = framework.module.fireAnim
			fireAnim = framework.viewmodel.AnimationController.Animator:LoadAnimation(fireAnim)
			
			fireSound = Instance.new("Sound")
			fireSound.Parent = character.UpperTorso
			fireSound.Name = "Fire"
			fireSound.SoundId = framework.module.fireSound.SoundId
		end

and also

if input.UserInputType	== Enum.UserInputType.MouseButton1 then
		if character and framework.viewmodel and framework.module then
			fireAnim:Play()
			character.UpperTorso.Fire:Play()
		end
	end
	
end)

if that is important

1 answer

It looks like there is a syntax error on the indicated line. The Lerp method should be called on a CFrame object, but it appears that aimCF is not defined as a CFrame object.

You can fix this error by making sure that aimCF is defined as a CFrame object before calling the Lerp method on it. For example, you could initialize aimCF to the identity CFrame at the beginning of your code using the following line of code:

local aimCF = CFrame.new()

Alternatively, you could define aimCF as a CFrame object using the CFrame.fromEulerAnglesXYZ method, which creates a CFrame from the specified Euler angles. For example:

local aimCF = CFrame.fromEulerAnglesXYZ(0, 0, 0)

Once you have defined aimCF as a CFrame object, you should be able to call the Lerp method on it without any issues.

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