I put the knockback coding into a touched event that has also a damage script in as well. The knockback works well and fine, but it knockbacks the dummy twice and not once. Any reasons why this is happening?
for i = 1,7 do
wait(.033)
gomuWeld.C1 = gomuWeld.C1 * CFrame.new(0.01, 0.1, 0)
gomuArm.Touched:Connect(function(hits)
if hits == nil then return end
if hits.Parent.Name == player.Name then return end
if hits.Parent:FindFirstChild("Humanoid") then
if hits.Parent:FindFirstChild("Pistol") == nil then
local debounce = Instance.new("BoolValue")
debounce.Parent = hits.Parent
debounce.Name = "Pistol"
if hits.Parent.Pistol.Value == false then
hits.Parent:FindFirstChild("Humanoid"):TakeDamage(30)
hits.Parent.Pistol.Value = true
wait(1)
if hits.Parent == nil then return end
hits.Parent.Pistol:Destroy()
end
end
local KnockBack = Instance.new("BodyVelocity")
KnockBack.Parent = hits.Parent:FindFirstChild("HumanoidRootPart")
KnockBack.MaxForce = Vector3.new(80000,80000,80000)
KnockBack.Velocity = character:FindFirstChild("HumanoidRootPart").CFrame.LookVector * 50 -- based on the direction YOUR character is facing.
game.Debris:AddItem(KnockBack, 0.1)
end
end)
end

1 comment
First of all i suggest you use else if statements. Especially on the debounce. And why don't you place the knockback part inside of the debounce part?