Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Knock-back part not knock backing enemies?

Asked by 2 years ago

So I made a wall that knocks back players this Is the script:

(BTW I DIDN'T ADD BODY VELOCITY BECAUSE ITS DEPCERATED)

script.Parent.Touched:Connect(function(hit)
    local humanoid = hit.Parent:WaitForChild("Humanoid")
    if humanoid then
        local KnockBack = Instance.new("VectorForce")

        KnockBack.Parent = humanoid.Parent
        KnockBack.Attachment0 = humanoid.Torso
        KnockBack.Force = Vector3.new(-1000,0,0)
    end
end)

1 answer

Log in to vote
1
Answered by 2 years ago

Hm, maybe try switching out :WaitForChild("Humanoid") for :FindFirstChild("Humanoid")?

Also, Attachment0 is for an attachment. Here, try this.

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

            Attachment.Parent = humanoid.Parent.Torso
            KnockBack.Parent = humanoid.Parent.Torso
            KnockBack.ApplyAtCenterOfMass = true
            KnockBack.Attachment0 = Attachment
            KnockBack.Force = Vector3.new(0,3000,6000)
            humanoid.Jump = true
            game:GetService("Debris"):AddItem(KnockBack,0.5)
            game:GetService("Debris"):AddItem(Attachment,0.5)
        end
    end
end)
0
Thanks! imnotaguest1121 362 — 2y
Ad

Answer this question