Why my script doesn't work?

Hey, i do not understand what is wrong with my script. Can anyone help me?

Error:

image

Folders:
image
image

SCRIPT:

local RunS = game:GetService("RunService")
local RepS = game:GetService("ReplicatedStorage")
local UIS = game:GetService("UserInputService")

local Char = script.Parent
local LeftShoulder = Char.Torso["Left Shoulder"]
local RightShoulder = Char.Torso["Right Shoulder"]

local Viewmodel = RepS.Viewmodels.Viewmodel:Clone()
Viewmodel.Parent = workspace.CurrentCamera



RunS.RenderStepped:Connect(function()
	
	local function ItemAnim (AnimationName,Play,Stop)
		
		for i,Reference in pairs(RepS.Items:GetChildren()) do
			
			local ItemName = Char:FindFirstChild(Reference.Name)
			
			if ItemName then
				
				local plr = game:GetService("Players").LocalPlayer
				
				local AnimFolder = plr.PlayerScripts:FindFirstChild(ItemName)
				
					local Anim = AnimFolder:WaitForChild(AnimationName)
				
					local LoadAnim = Char.Humanoid:LoadAnimation(Anim)
					
					LoadAnim:Play()
				
			end
		end
	end
	
	
	Viewmodel:SetPrimaryPartCFrame(workspace.CurrentCamera.CFrame)
	
	local Distance = (workspace.CurrentCamera.CFrame.Position - Char.Head.Position).Magnitude
	
	if Distance < 1 then
	
		
		
		ItemAnim("Idle",true,false)
	
		
		Char:FindFirstChild("Right Arm").LocalTransparencyModifier = .5 ; Char:FindFirstChild("Right Arm").CastShadow = false
		Char:FindFirstChild("Left Arm").LocalTransparencyModifier = .5 ; Char:FindFirstChild("Left Arm").CastShadow = false
	
		Char:FindFirstChild("Right Leg").LocalTransparencyModifier = .5 ; Char:FindFirstChild("Right Leg").CastShadow = false
		Char:FindFirstChild("Left Leg").LocalTransparencyModifier = .5 ; Char:FindFirstChild("Left Leg").CastShadow = false
		
		RightShoulder.Part0 = Viewmodel.Torso
		LeftShoulder.Part0 = Viewmodel.Torso
		
	else
		
		ItemAnim("Idle",false,true)
		
		RightShoulder.Part0 = Char.Torso
		LeftShoulder.Part0 = Char.Torso
	end
end)

local function onInputBegan(input,Processed)
	
	if UIS:IsMouseButtonPressed(Enum.UserInputType.MouseButton2) then
		print("Aiming")
		
		
		
	end
	
end

UIS.InputBegan:Connect(onInputBegan)

AnimFolder is a nil value. This is because FindFirstChild returns either an object or nil, depending on whether it can find the object.

I suggest printing the value of ItemName to see if that’s nil, too.

2 Likes

Thank you for responding. I printed the ItemName, here is results:

image

I’m assuming AK47 is the value of ItemName?

If so, are you sure AK47 is stored within LocalPlayer.PlayerScripts?

AK47 is a folder which contains animations

you can’t use the forum for someone to read your code and solve your problem, the forum is to ask for support for something you don’t know at all, not to look for free assistants.

Yea. I’m trying to understand why the script doesn’t find the animation

1 Like

you realize that the solution was given by @skipper987 you can’t wait for someone to fully explain your error, it’s simple verify that the animations folder is cloned in playerscripts, note that everything in playerscript is deleted or null so I recommend putting the folder somewhere else.

1 Like

Thank you. that’s what i needed. I spent 4 hours trying to fix this problem.

1 Like

hello what computer do you recommend to use blender?

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.