Attempt to index nil with 'IsPlaying'

  1. What do you want to achieve? I want to make a combat system. Right now im just making a punching tool with knockback.

  2. What is the issue? No matter how hard i try, it keeps saying “attempt to index nil with ‘IsPlaying’”

  3. What solutions have you tried so far? I removed an if statement and used a different method of knockback

Scripts:

Server:

local RemoteEvent = script.Parent.RemoteEvent

RemoteEvent.OnServerEvent:Connect(function(player, lookvector, mouseInstance, PlayAnim)
	
	local power = script.Parent.KnockbackPower.Value
		
	local human = mouseInstance.Parent.Parent:FindFirstChildOfClass("Humanoid") or mouseInstance.Parent:FindFirstChildOfClass("Humanoid")

	if human then

		local rootPart = human.Parent:FindFirstChild('HumanoidRootPart')
		local arm = human.Parent:FindFirstChild('Right Arm')


		if rootPart then

			if PlayAnim.IsPlaying then --If you're wondering, The error happens here
				if arm then
					arm.Touched:Connect(function()
						local blender = human.Parent:FindFirstChild("Head") 
						if not (blender == nil) then
							local bv = Instance.new("BodyVelocity")
							bv.P = 1250
							bv.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
							bv.Velocity = lookvector*-power
							bv.Parent = blender
							task.wait(.05)
							bv:Destroy()
							task.wait(.2)

						end
					end)
				end
			end
		end

	end
end)

Client:

local tool = script.Parent
local RemoteEvent = tool:WaitForChild('RemoteEvent')
local mouse = game.Players.LocalPlayer:GetMouse()
local Anim = Instance.new('Animation')
Anim.AnimationId = 'rbxassetid://10779704576'
PlayAnim = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(Anim)

tool.Activated:Connect(function()
	local mouseInstance = mouse.Target
	local lookvector = workspace.Camera.CFrame.LookVector
	
	PlayAnim:Play()		
	RemoteEvent:FireServer(lookvector, mouseInstance, PlayAnim)
	
end)

The reason is because the “PlayAnim” argument passed in is probably nil which is why the error occurs. Also, the “Humanoid:LoadAnimation()” is depreciated and you would probably see it underlined in orange or whatever your settings for it is so I suggest using an animator instead.

So, the IsPlaying property isn’t replicated from the client to the server, so that is one thing.

Second thing is, as @sata5pa3da said, you probably aren’t passing anything. I’d run if PlayAnim then to ensure it exists.

However, I must ask, why do you need this variable? If the remote only passes when they click (which plays the animation), why check if it is playing? You should avoid passing unnecessary variables & data through remotes, bad habit & poor optimisation.

I genuinely don’t know. I usually add unneccesary stuff and never realize so maybe thats why.

Also, removing the IsPlaying and switching to Animator (like @sata5pa3da said) led me to another error. On line 7 on the serverscript. Its saying “Parent is not a valid member of Vector3”. I dont have alot of experience with the Mouse instance, I used part of the code in DevHub so i dont exactly know how this works.

instead of detecting if the animation is playing, make a bool called “IsHitting” or something in the script, and replace the line if “PlayAnim.IsPlaying” then to


IsHitting = false

RemoteEvent.OnServerEvent:Connect(function()
if IsHitting == false then
IsHitting = true
-- Do stuff
PlayAnim.Stopped:Wait()
IsHitting = false
end
end)

Can you type the line out, please?

local human = mouseInstance.Parent.Parent:FindFirstChildOfClass("Humanoid") or mouseInstance.Parent:FindFirstChildOfClass("Humanoid")