Hello, I have been clueless since my script works the way I want it do work but it lags a little bit when applying knockback to another player, but when I get hit there is no lag? I have been trying to fix this since please help me!!
local function applyKnockback(character, plr, speed, upwardForce)
local humanoidRootPart = character:FindFirstChild("HumanoidRootPart")
local enemyPlayer = game.Players:GetPlayerFromCharacter(character)
if humanoidRootPart and enemyPlayer then
local isBlocking = enemyPlayer:FindFirstChild("isBlocking") and enemyPlayer.isBlocking.Value
if isBlocking then
speed = speed * 0.2
upwardForce = Vector3.new(0, 0, 0)
else
ragdollModule.EnableRagdoll(character)
end
local knockbackDirection = (humanoidRootPart.Position - plr.Character.HumanoidRootPart.Position).Unit
local combinedForce = (knockbackDirection + upwardForce).Unit
enemyPlayer:FindFirstChild("LastHit").Value = plr.Name
local bodyVelocity = Instance.new("BodyVelocity")
bodyVelocity.MaxForce = Vector3.new(9999, 9999, 9999)
bodyVelocity.Velocity = combinedForce * speed
bodyVelocity.Parent = humanoidRootPart
electricityEffect.Parent = humanoidRootPart
task.wait(0.1)
bodyVelocity:Destroy()
if not isBlocking then
Movement.disableMovement(character:FindFirstChild("Humanoid"))
task.wait(1.5)
ragdollModule.DisableRagdoll(character)
Movement.enableMovement(character:FindFirstChild("Humanoid"))
end
end
end
Imgur: The magic of the Internet (How I want it to be)
Imgur: The magic of the Internet (How mine is)
Imgur: The magic of the Internet (a better showcase of the problem look 1 player first then the other)