Problems with Knockback for Mobile Players

Introductory

Hello there!
I’m making a slap battles-like game called Brawl Business.

Problem

My current knockback script works for pc. However, when mobile players use shift lock, the point of the knockback script is pointless.

When players hit laptop/pc players, the knockback for them works as it should.
It rotates the player in the air.


–In this video, I’m PC and JersonMenciafam is Mobile–

However, for mobile players, when players hit mobile players, they don’t get a rotate velocity and they don’t knockback in the air.

Knockback Script:

local FightUtils = {}

function FightUtils:knockBack(pChar, eChar)
	local pHrp = pChar and pChar:FindFirstChild("HumanoidRootPart")
	local eHrp = eChar and eChar:FindFirstChild("HumanoidRootPart")

	if pHrp and eHrp then
		print("KB")
		local force = Instance.new("BodyVelocity")
		force.MaxForce = Vector3.new(10, 10, 10) * math.huge
		force.Velocity = pHrp.CFrame.LookVector * 50
		force.Parent = eHrp

		task.delay(0.25, function()
			force:Destroy()
		end)

		local rot = Instance.new("BodyAngularVelocity")
		rot.AngularVelocity = Vector3.one * math.pi * 2.5
		rot.MaxTorque = Vector3.one * math.huge
		rot.P = 10000
		rot.Parent = eHrp

		task.delay(0.25, function()
			rot:Destroy()
		end)
	end
end

return FightUtils

Can someone help me? Thanks!
(Also I want a knockback system like slap battles)

2 Likes

Do you need shiftlock to be on? You could try just disabling shift lock as a whole if you don’t need it.

1 Like

So if I understand correctly, the code doesn’t work while shift lock or first person is enabled?

I would try turning off AutoRotate while the character is being knocked back.

AutoRotate determines if first person or shift lock should rotate the character. While it is off everything works the exact same besides the character isn’t forced to face the direction of the camera.

https://developer.roblox.com/en-us/api-reference/property/Humanoid/AutoRotate

So in your code, for example, set Humanoid.AutoRotate to false, then inside the function given to task.delay set Humanoid.AutoRotate to true (regularly auto rotate is always true, so you don’t need to check the initial state).

Another thing, you probably want to set the humanoid state to HumanoidStateType.Ragdoll. In the first video, you apply enough force to automatically change the state to ragdoll. In the second video, the first person/shift lock setting overrides your force, causing the player to not automatically go into the ragdoll state. It is probably a good idea to just set the state to ragdoll so you don’t need to worry about weird cases like this one.

https://developer.roblox.com/en-us/api-reference/function/Humanoid/ChangeState

1 Like

Alright now I literally can’t even move my screen

Or maybe your trying to say turn it off then turn it on?

and i tried the humanoidstatetype.ragdoll thingy but it still gives me the same problem

Yes.


You need to set it on the client.

Here’s a few possible solutions I will list here:


Since you mentioned a system similar to Slap Battles, I would suggest using my Ragdoll 5.2 model, since it is fully compatible with R6.

Though, consider it a bandaid solution, since this model is quite outdated by now.

Ragdoll 5.2.rbxm (7.8 KB)
Please enable the script and put it into starter character scripts. You can then change some of the settings in the script itself. Disable some of them if they don’t work for you.

Then, to activate it, change the IsRagdoll BoolValue to true. It will then ragdoll for a set amount of time specified in RagdollTime, parented inside the value.


Another solution is using stateChanger, a solution I made for the 2020 version of Ragdoll 6, but it still works today. This module will change the state of the humanoid until you tell it to stop doing so. It will also do so on the server and client.

Ragdoll 6.1 stateChanger.rbxm (2.9 KB)

To use the module, please require it. Use StateChanger.StartRagdoll and StateChanger.StopRagdoll to start and stop changing the state. This script will do so from the server and client, but you must remember to stop the state change or else the script will cause issues (the player can’t get up).


PlatformStand is a property of Humanoid that determines if the player “can’t get up”. I suggest setting it to true for about 2 seconds and then to false.

it still somehow does not knockback the player

I would just momentarily platform stand them and aswell as turn off auto rotate, just like how @WarpedWormHole said.

AutoRotate is completely ignored with mobile shift lock.

if is like slap battles you are wanting a disable control ragdoll?

ya that’s exactly what i want for my game

you can disable autorotate and disabled after ragdoll time
exemple:

spawn(function) --reduce the risk of having the camera disabled for longer
local human = char:findfirstchild(“Humanoid”) --get the humanoid
human.AutoRotate = false --get camera controll and disable
wait(ragdolltime) --wait ragdoll time
human.AutoRotate = true --enable camera controll
end)
if its not the problem
try to make ragdolltime = knockback, Y Vector
slap battles ragdoll use BallSocketConstraint
in bodyparts
and bodyvelocity is deprecated try to use VectorVelocity
you can disable moviment in ragdoll time

Do I use it like this?

local FightUtils = {}

function FightUtils:knockBack(pChar, eChar, kB)
	local debris = game:GetService("Debris")
	local pHrp = pChar and pChar:FindFirstChild("HumanoidRootPart")
	local eHrp = eChar and eChar:FindFirstChild("HumanoidRootPart")

	if pHrp and eHrp then
		local pPlr = game.Players:GetPlayerFromCharacter(pChar)
		print("KB")
		local force = Instance.new("BodyVelocity")
		force.MaxForce = Vector3.new(10, 10, 10) * math.huge
		force.Velocity = pHrp.CFrame.LookVector * kB + Vector3.new(0, kB/2, 0)
		force.Parent = eHrp

		if force then
			debris:AddItem(force, 0.25)
		end

		local rot = Instance.new("BodyAngularVelocity")
		rot.AngularVelocity = Vector3.one * math.pi * 2.5
		rot.MaxTorque = Vector3.one * math.huge
		rot.P = 10000
		rot.Parent = eHrp

		if rot then
			debris:AddItem(rot, 0.25)
		end
		
		-- Apply ragdoll effect with BallSocketConstraints
		local attachments = {}
		for _, part in pairs(eChar:GetChildren()) do
			if part:IsA("BasePart") and part ~= eHrp then
				local attachment0 = Instance.new("Attachment")
				attachment0.Parent = part

				local attachment1 = Instance.new("Attachment")
				attachment1.Parent = eHrp

				local constraint = Instance.new("BallSocketConstraint")
				constraint.Attachment0 = attachment0
				constraint.Attachment1 = attachment1
				constraint.LimitsEnabled = true
				constraint.UpperAngle = 180
				constraint.TwistLimitsEnabled = true
				constraint.TwistUpperAngle = 180
				constraint.TwistLowerAngle = -180
				constraint.Parent = part

				table.insert(attachments, attachment0)
				table.insert(attachments, attachment1)

				debris:AddItem(constraint, 0.25)
			end
		end

		-- Disable movement during ragdoll time
		local humanoid = eChar:FindFirstChildOfClass("Humanoid")
		if humanoid then
			humanoid.PlatformStand = true
		end

		-- Re-enable movement after ragdoll time
		task.wait(0.25)
		if humanoid then
			humanoid.PlatformStand = false
		end
		
		-- Destroy attachments after ragdoll effect
		for _, attachment in pairs(attachments) do
			if attachment and attachment.Parent then
				attachment:Destroy()
			end
		end
	end
end

return FightUtils

Yeah,But you need disable character joints in ragdoll and enabled after,And you need a LocalScript changing the humanoid state for pyshical and after ragdoll gettingup, YOU NEED DISABLE AUTOROTATE and if its dont work try to disable mobile shiftlock when is ragdoll and enabled again