BodyVelocity making players disappear?

I have a glove script, and I’ve been getting people reporting that when they are slapped, they die randomly. I am assuming it’s the BodyVelocity, since I was once playing my game and I saw someone slap another person while they were on the floor and that person they slapped, suddenly died. But I also sometimes get normally slapped by someone, and I die randomly too. I really need some help.

Glove’s server script

playerslapped.OnServerEvent:Connect(function(player, targetedplayer, humanoid, targetedchar)
	if not slap.IsPlaying then
		slap:Play()
	end
	local targetHumanoid = targetedplayer:WaitForChild("HumanoidRootPart")
	local playerHumanoid = player.Character:WaitForChild("HumanoidRootPart")
	if targetHumanoid and playerHumanoid then
		local targetedplayerinstance = game:GetService("Players"):GetPlayerFromCharacter(targetedplayer)
		local velocity = Instance.new("BodyVelocity",targetedplayer.HumanoidRootPart)
		velocity.MaxForce = Vector3.new(4,4,4) * math.huge
		local dir = (targetedplayer.HumanoidRootPart.CFrame.Position - player.Character.HumanoidRootPart.Position).Unit
		velocity.Velocity = (dir + Vector3.new(0,0.7,0)).Unit *script.Parent.GloveStatsConfig.Power.Value

		local 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 = 5000
		targetedplayer.Humanoid:ChangeState(Enum.HumanoidStateType.Physics)
		ragdollmodule.Ragdoll(targetedplayer, targetedplayerinstance)
		game:GetService("Debris"):AddItem(velocity, 0.7)
		game:GetService("Debris"):AddItem(rot,0.7)
		task.wait(3)
		ragdollmodule.Stand(targetedplayer, targetedplayerinstance, targetedplayer.Humanoid)
		task.wait(0.5)
		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
				targetedplayer.Humanoid:ChangeState(Enum.HumanoidStateType.Physics)
			else
				ragdollmodule.Stand(targetedplayer, targetedplayerinstance, targetedplayer.Humanoid)
				targetedplayer.Humanoid:ChangeState(Enum.HumanoidStateType.Physics)
				found = nil
			end
		end
	end
end)
1 Like

Nevermind, I figured out how to prevent death. If you are trying to find a soloution, just simply disable death. :+1:

1 Like

Nevermind, it keeps making the player die.

1 Like

You seem to be using a lot of velocity here:
velocity.MaxForce = Vector3.new(4,4,4) * math.huge
Is it possible you are breaking the players neck weld which kills the player?

I can’t be sure but if you’re using R6 there is currently a bug that causes them to die for no reason using a combination of BallSocketConstraints. Disable BreakJointsOnDeath and it should virtually fix the issue, since you will still hear the death sound.

1 Like

So, do I disable it then I enable it afterwards?

What should I replace the maxforce with?

1 Like

Just play around with the value in your maxforce.
Lower it to just a small amount and see if that stops the player from dying. If so then only put enough maxforce to achieve the result you want.

It’s similar to putting a 1200 horsepower engine in a Yugo. It might work, but something’s going to break when you stomp your foot on the gas pedal!

Alright, I’ll try that. Thanks.

1 Like

Alright, I tried your idea. I put it to Vector3.new(2, 2, 2) instead and I also disabled BreakJointsOnDeath. Didn’t recieve any problems from testing, but if this works successfully in a regular server I will let you know. Thanks!

In addition to my previous post, I don’t believe that this bug occurs if you make the script a LocalScript (if it isn’t already), so if you still hear that death sound and it still causes issues, you can try making the script local.

Apparently, it’s still not fixed. It’s still happening.

I don’t hear death sounds, it’s just when I slap someone they disappear while they are in mid-air.

If they’re disappearing, it’s probably because of the max force but the root cause is probably because you are using the Vector3.Unit variable, which does not accept a value of zero.

I don’t understand this, I am kinda new to scripting. What should I change?

I guess changing the max force down like previously mentioned earlier in the thread should fix the issue.

I did change the MaxForce to Vector3.new(2,2,2) * math.huge

Make it Vector3.one * targetedplayer.HumanoidRootPart.AssemblyMass instead.

Okay, I’ll change it as soon as come home.

Like this?

velocity.MaxForce = Vector3.new(2,2,2) * Vector3.one * targetedplayer.HumanoidRootPart.AssemblyMass