Game bugs, HumanoidRootPart anchoring + Knockback not knocking back

Hi all! I have been making a battlegrounds game and along with the successes I have had many flaws. One of which is a few bugs that I don’t know how to patch.

A.) Sometimes the HumanoidRootPart anchors forever instead of for 0.5 seconds

B.) Sometimes the knockback doesn’t happen and just the knockback animation plays.
I’ve tried editing the scripts order and it didn’t work no matter what.

everything else is working perfectly, AND PLEASE DO NOT nitpick this post. yes my script is messy, but only say things that are DIRECTLY the problem. If you want to make my script perfect, do it yourself! Thank you in advance.

The code:
SERVER SIDE

local rs = game:GetService("ReplicatedStorage")
local TS = game:GetService("TweenService")
function Knockback(KnockbackSource, Player, Intensity)
	local bv = Instance.new("BodyVelocity")
	bv.MaxForce = Vector3.new(250000,250000,250000)
	bv.Velocity = -(KnockbackSource.Position - Player.HumanoidRootPart.Position).Unit*Intensity
	bv.Parent = Player
	game.Debris:AddItem(bv, 0.5)
end
rs.DamageDealer.OnServerEvent:Connect(function(plr, attackcycle, cooldown)
	if cooldown == true then
	local HRP = plr:FindFirstChild("HumanoidRootPart")
	local Params = RaycastParams.new()
	Params.FilterType = Enum.RaycastFilterType.Exclude
	Params.FilterDescendantsInstances = {plr.Character}
	rayDistance = 25 --// 3 studs
	origin = plr.Character:FindFirstChild("HumanoidRootPart").Position --// Position of the player
	direction = plr.Character:FindFirstChild("HumanoidRootPart").CFrame.LookVector * rayDistance --// Direction the player is looking * distance
	raycast = workspace:Raycast(origin, direction ,Params)
	
	local function Ray()
		return raycast and raycast.Position or origin + direction
	end

	print(Ray())
	print(plr.Character:FindFirstChild("Head").Orientation.X)


	if attackcycle == 1 then
		plr.Character:FindFirstChild("HumanoidRootPart").Anchored = true
		task.wait(0.01)
		local Football = game:GetService("ReplicatedStorage").Football:Clone()
		Football.Parent = workspace
		Football.Position = Vector3.new(plr.Character:WaitForChild("Left Leg").Position.X, plr.Character:WaitForChild("Left Leg").Position.Y, plr.Character:WaitForChild("Left Leg").Position.Z + 3)
		local Tweeninfo = TweenInfo.new(0.5, Enum.EasingStyle.Exponential, Enum.EasingDirection.Out, 0, false)
		local FootballTween = TS:Create(Football, Tweeninfo, {["Position"]=(Ray())})
		FootballTween:Play()
		plr.Character:FindFirstChild("HumanoidRootPart").Anchored = false
		FootballTween.Completed:Once(function()
			Football:Destroy()
			task.wait(0.2)
			plr.Character:FindFirstChild("HumanoidRootPart").Anchored = false
		end)
	end

	if attackcycle == 2 then
		plr.Character:FindFirstChild("HumanoidRootPart").Anchored = true
		task.wait(0.01)
		local Football = game:GetService("ReplicatedStorage").Football:Clone()
		local Tweeninfo = TweenInfo.new(0.5, Enum.EasingStyle.Exponential, Enum.EasingDirection.Out, 0, false)
		Football.Parent = workspace
		Football.Position = Vector3.new(plr.Character:WaitForChild("HumanoidRootPart").Position.X, plr.Character:WaitForChild("HumanoidRootPart").Position.Y, plr.Character:WaitForChild("HumanoidRootPart").Position.Z + 3)
		local FootballTween = TS:Create(Football, Tweeninfo, {["Position"]=(Ray())})
		FootballTween:Play()
		plr.Character:FindFirstChild("HumanoidRootPart").Anchored = false
		FootballTween.Completed:Once(function()
			Football:Destroy()
			task.wait(0.2)
	
		end)
	end

	if attackcycle == 3 then
		plr.Character:FindFirstChild("HumanoidRootPart").Anchored = true
		task.wait(0.01)
		local Football = game:GetService("ReplicatedStorage").Football:Clone()
		local SpecialTweeninfo = TweenInfo.new(0.25, Enum.EasingStyle.Exponential, Enum.EasingDirection.In, 0, false)
		Football.Parent = workspace
		Football.Position = Vector3.new(plr.Character:WaitForChild("Left Leg").Position.X, plr.Character:WaitForChild("Left Leg").Position.Y, plr.Character:WaitForChild("Left Leg").Position.Z + 3)

		local FootballTween = TS:Create(Football, SpecialTweeninfo, {["Position"]=(Ray())})
		FootballTween:Play()
		plr.Character:FindFirstChild("HumanoidRootPart").Anchored = false
		FootballTween.Completed:Once(function()
			FootballTween:Play()
			task.wait(0.25)
			Football:Destroy()
			task.wait(1)
	
		end)


	end

	if attackcycle == 4 then
		plr.Character:FindFirstChild("HumanoidRootPart").Anchored = true
		task.wait(0.01)
		local Football = game:GetService("ReplicatedStorage").Football:Clone()
		local SpecialTweeninfo = TweenInfo.new(0.125, Enum.EasingStyle.Exponential, Enum.EasingDirection.In, 0, false)
		Football.Parent = workspace
		Football.Position = Vector3.new(plr.Character:WaitForChild("Left Leg").Position.X, plr.Character:WaitForChild("Left Leg").Position.Y, plr.Character:WaitForChild("Left Leg").Position.Z + 3)

		local FootballTween = TS:Create(Football, SpecialTweeninfo, {["Position"]=(Ray())})
		FootballTween:Play()
		plr.Character:FindFirstChild("HumanoidRootPart").Anchored = false
		FootballTween.Completed:Once(function()
			FootballTween:Play()
			task.wait(0.2)
			Football:Destroy()
			task.wait(0.3)
	
		end)


	end


	--detects if it hit a part of a character with a humanoid
	if raycast and raycast.Instance.Parent:FindFirstChild("Humanoid") then
		local hum = raycast.Instance.Parent:FindFirstChild("Humanoid")
		local char = hum.Parent
		local humanoid = char:FindFirstChild("Humanoid")
		local humroot = char:FindFirstChild("HumanoidRootPart")
		local anim: Animator = hum:FindFirstChild("Animator")
		local animtrack = anim:LoadAnimation(script.Hit)
		animtrack:Play()
		char:FindFirstChild("Torso").Anchored = true
		if attackcycle == 1 or 2 or 3 or 4 then
			humanoid:TakeDamage(1)
			if attackcycle == 2 or 3 or 4 then
				humanoid:TakeDamage(2)
				if attackcycle == 3 or 4 then
					humanoid:TakeDamage(3)
					if attackcycle == 4 then
						humanoid:TakeDamage(4)
						rs.KnockbackGiverPlus:FireClient(game.Players:GetPlayerFromCharacter(char),humroot, plr)
						task.wait(0.5)
						char:FindFirstChild("Torso").Anchored = false
						local animtrack2 = anim:LoadAnimation(script.KnockedBack)
						animtrack2:Play()
						
				end
			end			
		end
		end
	end
	end 
	
end)

CLIENT SIDE



function KnockbackPlus(KnockbackSource, Player)
	local bv = Instance.new("BodyVelocity")
	bv.MaxForce = Vector3.new(250000,250000,250000)
	bv.Velocity = -(KnockbackSource.Position - Player.Position).Unit*125
	bv.Parent = Player
	game.Debris:AddItem(bv, 0.5)
end



game:GetService("ReplicatedStorage").KnockbackGiverPlus.OnClientEvent:Connect(function(humroot, plr)
	print("aaa I've been knocked")	
	KnockbackPlus(plr.Character.HumanoidRootPart, humroot)
end)

Again, help is appreciated but please don’t nitpick, it makes your point confusing (to me at least) and seems really confrontational to me!

You are setting humanoidrootpart.anchored to false before the tween completes

and for knockback not working I am not sure but it’s better to use assemblylinearvelocity or anything that isn’t deprecated. I think the issue might be related to your setup

I recommend to make the code more cleaner and easier to read to make it easier to debug code

I will try to fix that ty for your minimal nitpicking

ANYONE ELSE: The remaining problem is knockback being broken and only working hald the time

try assemblylinearvelocity instead of bodyvelocity and tell me if it works

ok! Thanks!

It’s just that the last guy who helped me tore apart my entire script saying it was way too messy because of this and that.
I get he was just trying to help but it didn’t really help as much as a straight answer

Is it ‘AssemblyLinearVelocity’ or just ‘LinearVelocity’ because I can’t find the former

AssemblyLinearVelocity it’s a property in all baseparts

Ohh a property ok ty [EXTRATEXT]

OH YEAH THAT WORKS. Absolutely amazingly.

( I exaggerated the knockback by A LOT.)

Glad I was able to help you

CHARACTERS

1 Like

Marked as solution, thanks a lot!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.