i have a punch script that should inflict knockback on the thing when it hits it. Though it wont work and I get this error:
Workspace.trueblockhead101.Punch.LocalScript:48: attempt to index nil with ‘CFrame’
local tool = script.Parent
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local InputService = game:GetService("UserInputService")
local InputType = Enum.UserInputType
local animation = nil
local slashAnimation = nil
tool.Equipped:Connect(function()
animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://7118111810"
slashAnimation = humanoid:LoadAnimation(animation)
end)
tool.Unequipped:Connect(function()
animation:Destroy()
slashAnimation = nil
end)
local debounce = false
InputService.InputBegan:Connect(function(input, processed)
if input.UserInputType == InputType.MouseButton1 and slashAnimation and not processed then
if debounce == false then
debounce = true
slashAnimation:Play()
local Connection
local tool = script.Parent
local function onTouch(partOther)
local humanOther = partOther.Parent:FindFirstChild("Humanoid")
if not humanOther then return end
if humanOther.Parent == tool then return end
humanOther:TakeDamage(5)
local KnockBack = Instance.new("BodyVelocity")
KnockBack.P = math.huge
KnockBack.Parent = humanOther:FindFirstChild("HumanoidRootPart")
KnockBack.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
KnockBack.Velocity = humanOther:FindFirstChild("HumanoidRootPart").CFrame.lookVector * -70
game.Debris:AddItem(KnockBack, 0.3)
if humanOther.Health <= 0 then
player.leaderstats.Souls.Value = player.leaderstats.Souls.Value + 1
humanOther.Parent:Destroy()
end
end
Connection = tool.Handle.Touched:Connect(onTouch)
slashAnimation.Stopped:Wait()
debounce = false
Connection:Disconnect()
wait(.2)
debounce = false
end
end
end)
Im honestly sure if i wrote the knock back script correctly, but im stumped.