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

Why does my knockback script pull the player to the ground and other problems?

Asked by 5 years ago

Code:

banana = script.Parent

function onTouch(hit)
    if hit.Parent == nil then return end
    local h = hit.Parent:FindFirstChild("Humanoid")
    if h ~= nil then
        local bv = Instance.new("BodyVelocity")
        bv.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
        bv.Parent = hit.Parent.UpperTorso
        bv.Velocity = hit.Parent.UpperTorso.Velocity.unit*-50
        wait(0.8)

        bv:Destroy()
    end
end
banana.Touched:connect(onTouch)

In this script I tried to make a knockback effect once the player touches this script's parent. The problem is, if the player, by some miracle, stands on the part one of these three things happen:

The knock back does its job and knocks the player up, the knock back drags the player to the ground until bv gets destroyed, or it kills the player instantly. I don't know how to fix this, somebody please help.

0
A gif of what is happening would also be helpful if this issue persists SerpentineKing 3885 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

Alright, so upon looking at your script, I added a debounce, like so:

local banana = script.Parent
local debounce = true

banana.Touched:Connect(function(hit)
if debounce == false then return end
debounce = false
    if hit.Parent == nil then return end
    local h = hit.Parent:FindFirstChild("Humanoid")
    if h ~= nil then
        local bv = Instance.new("BodyVelocity")
        bv.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
        bv.Parent = hit.Parent.UpperTorso
        bv.Velocity = hit.Parent.UpperTorso.Velocity.unit*-50
        wait(0.8)
        bv:Destroy()
    end
debounce = true
end)

This will prevent the function from being called multiple times.

The other concern you have is the player instantly dying. This is most likely a problem pertaining to the height limit of the workspace, meaning your "banana" is too close to the top of the workspace, try lowering your map's overall height (not the size, the position)

The only other problem I get is if you jump on the corner of the part, it makes the player spaz out, so you'll need to make sure the faces of the part are the most likely to be touched.

0
Functions are not fired. They are called. Please use the correct terminology. User#24403 69 — 5y
0
Wait i will try this once i get back xXKingCool258Xx 39 — 5y
Ad

Answer this question