Basically, I have a knockback script as well as a ragdoll script. Whenever an enemy player gets hit with a weapon, the knockback and ragdoll will activate on that enemy player.
Whenever the player is getting knocked back, there’s a chance the enemy player lands on its feet, and that makes the ragdoll weird.
In order to fix it, I’ve tried making the CFrame of the enemy players humanoid root part face the sky, but it didn’t work.
Here’s my knockback code.
local force = Instance.new("BodyVelocity", eHrp)
force.MaxForce = Vector3.new(1, 1, 1) * math.huge
local dir = (eHrp.CFrame.Position - pHrp.CFrame.Position).Unit
force.Velocity = (dir + Vector3.new(0, 0.7, 0)). Unit * Power * 0.8
game.Debris:AddItem(force, .25)
local rot = Instance.new("BodyAngularVelocity", eHrp)
rot.AngularVelocity = Vector3.new(1, 1, 1) * math.pi * 0.2
rot.MaxTorque = Vector3.new(1, 1, 1) * math.huge
rot.P = 10000
game.Debris:AddItem(rot, .25)
The problem is not in the knockback script it’s in the ragdoll some solutions are enabling platformStanding (a Humanoid proprety) or create another local script fire a remoteEvent when you ragdoll the player and disable the GettingUP humanoidState and set the humanoidState to physics in the local script
In the server script you should have the ragdoll event when you want to ragdoll a player fire this event to the player that’s going to be ragdolled and pass the player that’s going to ragdolled i’m going to call playerTarget event:FireClient(playerTarget,"Ragdoll") you also need to pass a string to know if we’re going to ragdoll the player or not
Then on the local script you should do this
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ragdollEvent = ReplicatedStorage:WaitForChild("Events"):WaitForChild("ModuleEvents"):WaitForChild("Ragdoll")
ragdollEvent.OnClientEvent:Connect(function(context)
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait() -- You need to put this inside of the onClientEvent so as to get the new character that gets added after the player dies if we don't do this then if the player dies this script won't work
local humanoid :Humanoid = character:WaitForChild("Humanoid")
if context == "Ragdoll" then
humanoid:SetStateEnabled(Enum.HumanoidStateType.GettingUp,false)
humanoid:ChangeState(Enum.HumanoidStateType.Physics)
elseif context == "UnRagdoll" then
humanoid:SetStateEnabled(Enum.HumanoidStateType.GettingUp,true)
humanoid:SetStateEnabled(Enum.HumanoidStateType.Running,true)
humanoid:ChangeState(Enum.HumanoidStateType.GettingUp) -- we change the state to getting up well to make the player get up
end
end)