I’m creating a combat system and have been trying to add knockback to the last hit of every combo but for some reason it lags when the player attacks a dummy, but not when the dummy attacks a player.
function combatModule.Push(character, root, pushDir, combo, isAttacker)
if isAttacker and combo == 4 then return end
local attachment = Instance.new("Attachment", root)
local linearVelocity = Instance.new("LinearVelocity", root)
linearVelocity.Attachment0 = attachment
linearVelocity.MaxForce = 1e7
linearVelocity.VelocityConstraintMode = Enum.VelocityConstraintMode.Vector
linearVelocity.VectorVelocity = pushDir * 3
game.Debris:AddItem(attachment,0.3)
end
This is where the function is being called for reference.
-- Setup animation and push force
local gettingHitAnim = script.gettingHitAnims["gettingHit" .. combo]
local punchVFX = rs.Particles.punchVFX
local pushForce = (combo == 4) and 10 or 0 -- If combo == 4 push with __ value else do __ value
local pushDirection = plrRoot.CFrame.LookVector * pushForce
local hitStun = hitHum:GetAttribute("hitStun")
local hitIsDummy = hitChar:FindFirstChild("ReviveScript") ~= nil
local hitPlr = game.Players:GetPlayerFromCharacter(hitChar)
if hitIsDummy then
-- If a plr hits a dummy, it fires to the server from that players client
pushRemote:FireServer(hitChar, hitRoot, pushDirection, combo, false, hitIsDummy, hitStun)
damageRemote:FireServer(hit, 5, gettingHitAnim)
else if runService:IsClient() then
--If your hitting a plr as a plr
pushRemote:FireServer(hitPlr, hitRoot, pushDirection, combo, false, false, hitStun)
damageRemote:FireServer(hit, 5, gettingHitAnim)
pushRemote:FireServer(player, plrRoot, pushDirection, combo, true, hitStun)
else
-- If a dummy is hitting a plr
combatModule.Push(hitPlr, hitRoot, pushDirection, combo, false)
hitHum:TakeDamage(5)
gettingHitRemote:FireClient(hitPlr, gettingHitAnim, combo)
end
Fires to the pushRemote are to prevent pushes from happening client side since then they wont replicate to other players clients. Heres the pushRemote script if it matters aswell.
--This script just makes sure that the push runs on the server to prevent client side bugs
local rs = game.ReplicatedStorage
local runService = game["Run Service"]
local pushRemote = rs.serverRemotes.pushRemote
local combatModule = require(rs.CombatModules.hitDetectionModule)
pushRemote.OnServerEvent:Connect(function(player, plr, root, pushDir, combo, attacker, hitStun)
combatModule.Push(plr, root, pushDir, combo, attacker)
end)
Hitting Dummy:
Getting Hit: