Knockback not exactly working?
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
01 | game.ReplicatedStorage.Bat.OnServerEvent:Connect( function (player) |
02 | local debounce = false |
03 | local char = player.Character or player.CharacterAdded:Wait() |
04 | local tool = char:FindFirstChild( "Bat" ) |
07 | local RegionPos 1 = bat.Handle.hitbox.Position - (bat.Handle.hitbox.Size / 2 ) |
08 | local RegionPos 2 = bat.Handle.hitbox.Position + (bat.Handle.hitbox.Size / 2 ) |
09 | local HitboxRegion = Region 3. new(RegionPos 1 , RegionPos 2 ) |
13 | bat.Handle.SWING:Play() |
17 | local BodyPartsInRegion = workspace:FindPartsInRegion 3 (HitboxRegion, nil , 1000 ) |
21 | for index, hit in pairs (BodyPartsInRegion) do |
22 | local HitCharacter = hit.Parent |
23 | local HitHumanoid = HitCharacter:FindFirstChildOfClass( "Humanoid" ) |
24 | local HitTorso = HitCharacter:FindFirstChild( "HumanoidRootPart" ) |
25 | local HitHead = HitCharacter:FindFirstChild( "Head" ) |
26 | local HitPlayer = game:GetService( "Players" ):GetPlayerFromCharacter(HitCharacter) |
30 | if (HitCharacter ~ = nil ) and (HitHumanoid ~ = nil ) and (HitTorso ~ = nil ) and (HitHead ~ = nil ) then |
32 | if HitCharacter.Name ~ = player.Name then |
34 | if debounce = = false then |
36 | bat.Handle.BIGHIT:Play() |
37 | game.ReplicatedStorage.Boom:FireAllClients() |
38 | local boom 1 = bat.Handle.hit 1 :Clone() |
39 | local boom 2 = bat.Handle.hit 2 :Clone() |
40 | boom 1. Parent = HitTorso |
41 | boom 2. Parent = HitTorso |
44 | HitHumanoid.Jump = true |
45 | HitTorso.Velocity = (player.Character or player.CharacterAdded:Wait()):FindFirstChild( "HumanoidRootPart" ).CFrame.LookVector * 200 + Vector 3. new( 0 , 30 , 0 ) |
49 | game.Debris:AddItem(boom 1 , 1 ) |
50 | game.Debris:AddItem(boom 2 , 1 ) |
54 | HitHumanoid:TakeDamage(damage) |
56 | local CreatorTag = Instance.new( "ObjectValue" ) |
57 | CreatorTag.Name = "creator" |
58 | CreatorTag.Value = player |
59 | CreatorTag.Parent = HitHumanoid |
60 | game.Debris:AddItem(CreatorTag, 3 ) |