Hi, so i asked a question similar to this about knockback not working before for a tool i was making, but the thing is that now it seems to sort of have the chance to do it only for a split second, and doesnt give the player a chance to actually hit the other person, I've been trying all kinds of things but they just wont work. Help would be appreciated!
heres the script in serverscript service that gets activated from a tool when they press e
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 SlashInstanceValue = Instance.new("StringValue")
SlashInstanceValue.Name = "toolanim"
SlashInstanceValue.Value = "Slash"
SlashInstanceValue.Parent = 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
wait(0.5)
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)
