Players keep flying around sometimes

I always keep reciving issues from my glove system, I’ve been fixing them lately. But the one I haven’t been able to crack down was the weird flying glitch.


Explaination

Whenever a player gets slapped, there is a chance that they will start flying around everywhere and they won’t stop until they get slapped.

Glove’s script

local targetHumanoidRP : BasePart = targetedplayer:WaitForChild("HumanoidRootPart")
	local playerHumanoidRP : BasePart = player.Character:WaitForChild("HumanoidRootPart")
	local targethumanoid : Humanoid = targetedplayer.Humanoid
	-- If target's humanoid and player's humanoid was found
	if targetHumanoidRP and playerHumanoidRP then	
		-- Creating BodyVelocity and BodyAngularVelocity
		targetedplayer.Humanoid.WalkSpeed = 0
		local targetedplayerinstance = game:GetService("Players"):GetPlayerFromCharacter(targetedplayer)
		local velocity
		local rot
		velocity = Instance.new("BodyVelocity",targetedplayer.HumanoidRootPart)
		velocity.MaxForce = Vector3.new(2,2,2) * math.huge
		local dir = (targetedplayer.HumanoidRootPart.CFrame.Position - player.Character.HumanoidRootPart.Position).Unit
		velocity.Velocity = Vector3.new(playerHumanoidRP.CFrame.LookVector.X * script.Parent.GloveStatsConfig.Power.Value, 1.5, playerHumanoidRP.CFrame.LookVector.Z * script.Parent.GloveStatsConfig.Power.Value) 
		rot = Instance.new("BodyAngularVelocity",targetedplayer.HumanoidRootPart)
		rot.AngularVelocity = Vector3.new(1,2,1) * math.pi * 5
		rot.MaxTorque = Vector3.new(2,5,2) * math.huge
		rot.P = 10000 --used to be 5k
		-- Makes player in a falling position, then ragdolls
		targethumanoid.RequiresNeck = false	
		targetedplayer.PreventFlopping1.Disabled = false
		targetedplayer.PreventFlopping2.Disabled = false
		betterragdollmodule:Ragdoll(targetedplayer)
		game:GetService("Debris"):AddItem(velocity, 0.7)
		game:GetService("Debris"):AddItem(rot,0.7)
		targethumanoid:SetStateEnabled(Enum.HumanoidStateType.GettingUp, false)
		task.wait(4)
		targetedplayer.PreventFlopping1.Disabled = true
		targetedplayer.PreventFlopping2.Disabled = true
		targethumanoid.RequiresNeck = true
		targethumanoid.PlatformStand = false	
		-- Ragdolls player
		betterragdollmodule:Unragdoll(targetedplayer)
		betterragdollmodule:Unragdoll(targetedplayer)
		targethumanoid:SetStateEnabled(Enum.HumanoidStateType.GettingUp, true)
		script.Parent.GettingUpEvent:FireAllClients(targethumanoid)
		-- If Ragdoll instances found, then repeat standing up, since in most cases target can ragdoll while standing
		if targetedchar:FindFirstChild("Humanoid") then
			local a = targetedchar
			for _, instance in pairs(targetedchar:GetDescendants()) do
				if instance:IsA("BallSocketConstraint") then
					found = true
				end
			end
			if found == nil then
				script.Parent.GettingUpEvent:FireAllClients(targethumanoid)
			else
				repeat
					wait()
					betterragdollmodule:Unragdoll(targetedplayer)
				until targetedchar.Parent.HumanoidRootPart.BallSocketConstraint.Parent == nil
				betterragdollmodule:Unragdoll(targetedplayer)
				script.Parent.GettingUpEvent:FireAllClients(targethumanoid)
				found = nil
			end
		end
		task.wait(0.5)
		script.Parent.GettingUpEvent:FireAllClients(targethumanoid)
		betterragdollmodule:Unragdoll(targetedplayer)	
	end

BodyVelocity is deprecated and its behaviour unpredictable. Use LinearVelocity or VectorForce from now on.

If you need a consistent velocity, use LinearVelocity, if you want to continually apply a force to something use VectorForce, and if you want to apply a one-time force use BasePart:ApplyImpulse().

Switching to one of these that bests suits you may fix your problem but if it doesn’t or you need help switching over, don’t hesitate to ask for more help here.

BetterRagdollModule.lua

– Checks if BallSocketConstraint exists in character
function BetterRagdoll:IsRagdoll(player)
local char = player.Character
local found = false
for _, instance in pairs(char:GetDescendants()) do
if instance:IsA(“BallSocketConstraint”) then
found = true
end
end
return found
end

– Unragdolls the player
function BetterRagdoll:Unragdoll(player,bypass)
local char = player.Character
local found = false
if not bypass then
for _, instance in pairs(char:GetDescendants()) do
if instance:IsA(“BallSocketConstraint”) then
found = true
end
end
end
if found == true or bypass then
local h = char:FindFirstChild(“Humanoid”)
if h then
h.PlatformStand = false
h:ChangeState(Enum.HumanoidStateType.GettingUp)
end
end
end

– Ragdolls the player
function BetterRagdoll:Ragdoll(player)
local char = player.Character
local found = false
for _, instance in pairs(char:GetDescendants()) do
if instance:IsA(“BallSocketConstraint”) then
found = true
end
end
if found == nil then
local h = char:FindFirstChild(“Humanoid”)
if h then
h.PlatformStand = true
h.Health = 0
h:ChangeState(Enum.HumanoidStateType.Dead)
end
end
end

– Returns whether or not player is ragdolled
function BetterRagdoll:CanGetUp(player)
local char = player.Character
local found = false
return not BetterRagdoll:IsRagdoll(player)
end

– Returns whether or not player is ragdolled
function BetterRagdoll:Ragdolling(player)
local char = player.Character
local found = false
return BetterRagdoll:IsRagdoll(player)
end

– Returns whether or not player is getting up
function BetterRagdoll:GettingUp(player)
local char = player.Character
local found = false
local cangetup = false
for _, instance in pairs(char:GetDescendants()) do
if instance:IsA(“BallSocketConstraint”) then
found = true
end
end
if found == nil then
local h = char:FindFirstChild(“Humanoid”)
if h then
if h.State == Enum.HumanoidStateType.GettingUp then
cangetup = true
end
end
end
return cangetup
end

– Returns whether or not player is getting up
function BetterRagdoll:IsGettingUp(player)
local char = player.Character
local found = false
local cangetup = false
for _, instance in pairs(char:GetDescendants()) do
if instance:IsA(“BallSocketConstraint”) then
found = true
end
end
if found == nil then
local h = char:FindFirstChild(“Humanoid”)
if h then
if h.State == Enum.HumanoidStateType.GettingUp then
cangetup = true
end
end
end
return cangetup
end

– Returns whether or not player is getting up
function BetterRagdoll:IsStanding(player)
local char = player.Character
local found = false
local cangetup = false
for _, instance in pairs(char:GetDescendants()) do
if instance:IsA(“BallSocketConstraint”) then
found = true
end
end
if found == nil then
local h = char:FindFirstChild(“Humanoid”)
if h then
if h.State ~= Enum.HumanoidStateType.GettingUp then
cangetup = true
end
end
end
return cangetup
end

– Returns whether or not player is getting up
function BetterRagdoll:CanRagdoll(player)
local char = player.Character
local found = false
local cangetup = false
for _, instance in pairs(char:GetDescendants()) do
if instance:IsA(“BallSocketConstraint”) then

I am not using that, because I am not trying to kill the player that is the thing I am trying to prevent.