So I have issue with my knockback. There is no errors and script works correctly but only one thing I don’t like is slow knockback. When I hit a dummy, dummy reacts to my knockback very slowly. For example, when I hit the dummy once, the dummy gets knockback after few seconds and I want it reacts to my hit immediately.
Here is the video of the issue:
here is the placements of scripts
here is the script in Module script called as “Hit System From Server”
local StunHandler = require(script.StunHandlerV2)
local module = {}
function module.hit(Humanoid, Damage, stun, enemyPlayer, Combo, MaximumCombo)
Humanoid:TakeDamage(Damage)
StunHandler.Stun(Humanoid, stun)
------------------------------------
-- Enemy player hit animation function
if enemyPlayer then
local body = Instance.new("BodyVelocity")
body.MaxForce = Vector3.new(1, 1, 1) * math.huge
body.Velocity = enemyPlayer
body.Parent = Humanoid.RootPart
body.P = 5000
game.Debris:AddItem(body, .1)
if Combo < MaximumCombo then
body.Velocity = enemyPlayer * 10
else
body.Velocity = enemyPlayer * 100
end
end
------------------------------------
end
return module
Is StunHandler doing something to the enemy that’s preventing them from moving right away? I’m not familiar with StunHandler. Other than that, I can’t tell why it lags that far behind. Maybe it’s due to server-client latency.
As a side note though, BodyVelocity is deprecated and LinearVelocity should be used instead.
About BodyVelocity being deprecated. Honestly, replaces for these “deprecated” instances like bodyVelocity are awful at the point of replication (this was tested by a lot of people including me). So, basically, if you are not creating velocity on the client, you should use BodyVelocity since it’s being replicated more properly
it does not work. Even dummies animation starts very slowly.
But it should not be like that as I placed their animation in my script in ServerScriptService here
local Event = game.ReplicatedStorage:WaitForChild("Combat Event")
local Server_Hit = require(game.ServerStorage["Hit System from Server"])
local MaxCombo = 4
local Module = require(game.ServerStorage.MuchachoHitbox)
local attacking = false
-- Combo Function!
-----------------------------------
local function Combo_Func(Character)
local Combo = Character:GetAttribute("Combo")
if Combo < MaxCombo then
Character:SetAttribute("Combo", Combo + 1)
else
Character:SetAttribute("Combo", 1)
end
end
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(chr)
chr:SetAttribute("Combo", 1)
end)
end)
-----------------
Event.OnServerEvent:Connect(function(plr)
local chr = plr.Character
-- Humanoid
local Hum = chr:WaitForChild("Humanoid")
local animator = Hum:WaitForChild("Animator")
local Root = chr:WaitForChild("HumanoidRootPart")
local Combo = chr:GetAttribute("Combo")
local Animations = game.ReplicatedStorage["Bacon Animations"]:GetChildren()
local Load_chr_anim = animator:LoadAnimation(Animations[Combo])
-----------------------------------------------------------------
-- creating a hitbox
local Hitbox = Module.CreateHitbox()
Hitbox.Size = Vector3.new(4.5, 4.5, 4.5)
Hitbox.Offset = CFrame.new(0, 1, -2.4)
Hitbox.CFrame = Root
if attacking then return end
attacking = true
Load_chr_anim.Stopped:Connect(function()
Hum.WalkSpeed = 16
attacking = false
Hitbox:Stop()
end)
Hitbox.Touched:Connect(function(hit, Humanoid)
if Humanoid == Hum then return end
local M1_sound = game.ReplicatedStorage.Sounds:WaitForChild("Cartoon Punch Sound Effect"):Clone()
local M2_sound = game.ReplicatedStorage.Sounds:WaitForChild("Punch Sound Effect Sfx "):Clone()
local M3_sound = game.ReplicatedStorage.Sounds:WaitForChild("Punch Sound Effect Sfx 2 "):Clone()
local M4_sound = game.ReplicatedStorage.Sounds:WaitForChild("DBZ Punch Sound"):Clone()
M1_sound.Parent = Root
M2_sound.Parent = Root
M3_sound.Parent = Root
M4_sound.Parent = Root
local hitAnim = game.ReplicatedStorage["Hit Animation"]:GetChildren()
local Load_Hit
if Combo == 1 then
M1_sound:Play()
wait(1)
M1_sound:Remove()
Load_Hit = Humanoid:LoadAnimation(hitAnim[1])
elseif Combo == 2 then
M2_sound:Play()
wait(1)
M2_sound:Remove()
Load_Hit = Humanoid:LoadAnimation(hitAnim[1])
elseif Combo == 3 then
M3_sound:Play()
wait(1)
M3_sound:Remove()
Load_Hit = Humanoid:LoadAnimation(hitAnim[1])
elseif Combo == 4 then
M4_sound:Play()
wait(1)
M4_sound:Remove()
Load_Hit = Humanoid:LoadAnimation(hitAnim[1])
end
Load_Hit:Play()
Server_Hit.hit(Humanoid, 4.21, 10, Root.CFrame.LookVector, Combo, MaxCombo)
end)
-----------------------------------------------------------------
Combo_Func(chr)
Load_chr_anim:Play()
task.wait(.1)
Hitbox:Start()
wait(0.5)
if attacking and Combo == MaxCombo and Hum.WalkSpeed ~= 16 then
Hum.WalkSpeed = 8
end
end)
Nevermind I fixed it!
I just needed to replace some codes in the script. It was the issue with wait()
I also tried LinearVelocity again and it worked but it wasn’t that smooth so I again switched to BodyVelocity. Now it works great after I found the issue. Thank you for helping