Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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.

1 comment

0

A gif of what is happening would also be helpful if this issue persists

1 answer

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.

2 comments

0

Functions are not fired. They are called. Please use the correct terminology.

0

Wait i will try this once i get back

This discussion is preserved as it was. New answers, comments, and votes are closed.