so i have this module that has 2 functions of kb and ragdoll it works fine on npcs but on players it like bugs out probably cuz npcs are server sided how do i make it work on both:
local module = {}
function module.Ragdoll(hitCharacter)
if not game:GetService("CollectionService"):HasTag(hitCharacter, "NoRagdoll") then
local humanoid = hitCharacter:FindFirstChild("Humanoid")
if humanoid and not hitCharacter:FindFirstChild("RagdollModel") then
local ragdollModel = script:FindFirstChild("RagdollModel"):Clone()
ragdollModel.Parent = hitCharacter
ragdollModel.Falllol.Disabled = false
hitCharacter.Stun.Value = true
humanoid:ChangeState(Enum.HumanoidStateType.FallingDown)
local middle = ragdollModel:FindFirstChild("Middle")
if not middle then return end
for _, part in ipairs(ragdollModel:GetChildren()) do
if part:IsA("Part") then
local weld = Instance.new("BallSocketConstraint")
local attach0 = Instance.new("Attachment", middle)
local attach1 = Instance.new("Attachment", part)
weld.Attachment0 = attach0
weld.Attachment1 = attach1
weld.Parent = middle
end
end
humanoid.PlatformStand = true
for _, item in ipairs(ragdollModel:GetChildren()) do
if item:IsA("BasePart") then
item.Anchored = false
item.CanCollide = true
end
end
task.delay(3, function()
local humanoid = hitCharacter:FindFirstChild("Humanoid")
local rootPart = hitCharacter:FindFirstChild("HumanoidRootPart")
if humanoid and rootPart and humanoid.Health > 0 then
humanoid.PlatformStand = false
--
local newPosition = rootPart.Position + Vector3.new(0, 1, 0)
rootPart.CFrame = CFrame.new(newPosition) * rootPart.CFrame.Rotation
end
end)
end
end
end
function module.KB(hitCharacter, sourcePosition, multiplier)
local humanoidRootPart = hitCharacter:FindFirstChild("HumanoidRootPart")
if humanoidRootPart then
humanoidRootPart:SetNetworkOwner(nil)
local direction = (humanoidRootPart.Position - sourcePosition).Unit
local knockbackForce = Vector3.new(direction.X, 0.1, direction.Z).Unit * multiplier
humanoidRootPart:ApplyImpulse(knockbackForce)
task.delay(0.5, function()
local player = game.Players:GetPlayerFromCharacter(hitCharacter)
if player then
humanoidRootPart:SetNetworkOwner(player)
end
end)
end
end
return module