hi, so basically i have a knockback system for a bat i made, but the knockback only seems to work for a split second, and even though ive tried like adding waits, it either does it at the very start, or just doesnt do it at all. Help would be appreciated
Here is the script that gets activated when a remote event is fired
game.ReplicatedStorage.Bat.OnServerEvent:Connect(function(player)
local debounce = false
local char = player.Character or player.CharacterAdded:Wait()
local tool = char:FindFirstChild("Bat")
local bat = tool
local RegionPos1 = bat.Handle.hitbox.Position - (bat.Handle.hitbox.Size / 2)
local RegionPos2 = bat.Handle.hitbox.Position + (bat.Handle.hitbox.Size / 2)
local HitboxRegion = Region3.new(RegionPos1, RegionPos2)
task.wait(1)
bat.Handle.SWING:Play()
local BodyPartsInRegion = workspace:FindPartsInRegion3(HitboxRegion, nil, 1000)
for index, hit in pairs(BodyPartsInRegion) do
local HitCharacter = hit.Parent
local HitHumanoid = HitCharacter:FindFirstChildOfClass("Humanoid")
local HitTorso = HitCharacter:FindFirstChild("HumanoidRootPart")
local HitHead = HitCharacter:FindFirstChild("Head")
local HitPlayer = game:GetService("Players"):GetPlayerFromCharacter(HitCharacter)
local damage = 20
if (HitCharacter ~= nil) and (HitHumanoid ~= nil) and (HitTorso ~= nil) and (HitHead ~= nil) then
if HitCharacter.Name ~= player.Name then
if debounce == false then
debounce = true
bat.Handle.BIGHIT:Play()
game.ReplicatedStorage.Boom:FireAllClients()
local boom1 = bat.Handle.hit1:Clone()
local boom2 = bat.Handle.hit2:Clone()
boom1.Parent = HitTorso
boom2.Parent = HitTorso
boom1.Enabled = true
boom2.Enabled = true
HitHumanoid.Jump = true
HitTorso.Velocity = (player.Character or player.CharacterAdded:Wait()):FindFirstChild("HumanoidRootPart").CFrame.LookVector * 200 + Vector3.new(0, 30, 0)
wait(0.4)
boom1.Enabled = false
boom2.Enabled = false
game.Debris:AddItem(boom1, 1)
game.Debris:AddItem(boom2, 1)
HitHumanoid:TakeDamage(damage)
local CreatorTag = Instance.new("ObjectValue")
CreatorTag.Name = "creator"
CreatorTag.Value = player
CreatorTag.Parent = HitHumanoid
game.Debris:AddItem(CreatorTag, 3)
end
end
end
end
end)

3 comments
Thank you so much! it works!
You have no idea how long ive been looking for this, so thanks again!
No Problem!