-
What do you want to achieve? I want to make a combat system. Right now im just making a punching tool with knockback.
-
What is the issue? No matter how hard i try, it keeps saying “attempt to index nil with ‘IsPlaying’”
-
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)