Ad
Log in to vote
0

Knockback not exactly working?

Asked by 26 days ago

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)

1 answer

Log in to vote
1
Answered by 26 days ago

I think I found your problem

I saw:

 HitTorso.Velocity

In your code and Velocity Is Deprecated meaning It will no longer work on new work

I decided to put this script Inside of a part which knockbacks players away from It:

script.Parent.Touched:Connect(function(hit)
    local humanoid = hit.Parent:FindFirstChild("Humanoid")
    if humanoid then
        if not humanoid.Parent.Torso:FindFirstChild("VectorForce") then
            local VectorForce = Instance.new("VectorForce")
            local Attachment = Instance.new("Attachment")

            VectorForce.Parent = humanoid.Parent.Torso
            Attachment.Parent = humanoid.Parent.Torso
            VectorForce.Force = Vector3.new(0,300,6000)
            VectorForce.Attachment0 = Attachment
            VectorForce.ApplyAtCenterOfMass = true
            humanoid.Jump = true
            game:GetService("Debris"):AddItem(VectorForce,0.5)
            game:GetService("Debris"):AddItem(Attachment,0.5)
        end
    end
end)
0
Thank you so much! it works! DriBowser 55 — 26d
0
You have no idea how long ive been looking for this, so thanks again! DriBowser 55 — 26d
0
No Problem! imnotaguest1121 186 — 25d
Ad

Answer this question