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.
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.