I’m making a combat system that would seem to be going well in studio until I try it in an actual game.
In studio everything is working very smooth and works nice, but when I join the actual game I get really bad input lag and some hits don’t even register
Studio
In Game
I’ve tried lowering cooldowns but it still happens
The client controls all effects while the server only handles the damaging and cooldowns
The only code the tool uses
ReplicatedStorage = game:GetService("ReplicatedStorage")
UserInput = game:GetService("UserInputService")
--// Player Variables \\--
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
local hitbox = game.Workspace.R.Hitboxes:WaitForChild(player.UserId)
--// Script Variables \\--
local tool = script.Parent
local currentTime = tick()
local CurrentCombo
local cd = .3
--// Modules \\--
local StateController = require(ReplicatedStorage.Modules.StateController)
local EffectRunner = require(ReplicatedStorage.Modules.EffectRunner)
--// Animations \\--
local idle
local m1
local m2
local m3
local m4
local m5
local heavyPunch
local clicked = false
local clickDebounce = false
local Animations = {
idle;
m1;
m2;
m3;
m4;
m5;
heavyPunch;
}
--// Sounds \\--
local m1Swing = ReplicatedStorage.Sounds.Fist.PunchSwing
local m2Swing = ReplicatedStorage.Sounds.Fist.HeavySwing
--// Remotes \\--
local BasicAttackEvent = ReplicatedStorage.Remotes.Main.Combat
local args = {}
args.HeavyAttack = false
--// Functions \\--
function m1Punch()
if StateController:CanM1(hitbox) then
args.HeavyAttack = false
BasicAttackEvent:FireServer("basicAttack", args)
CurrentCombo = hitbox:GetAttribute("Combo")
if CurrentCombo > 1 then
Animations[CurrentCombo-1]:Stop()
end
Animations[CurrentCombo]:Play()
m1Swing:Play()
args.HeavyAttack = false
clicked = true
end
end
function m2Punch()
if StateController:CanM2(hitbox) then
args.HeavyAttack = true
BasicAttackEvent:FireServer("basicAttack", args)
Animations[6]:Play()
task.wait(.1)
Animations[6]:AdjustSpeed(0.3)
task.wait(.2)
Animations[6]:AdjustSpeed(1)
m2Swing:Play()
clicked = false
return true
end
end
function coolDown()
if tick() - currentTime >= cd then
currentTime = tick()
return true
end
return false
end
tool.Equipped:Connect(function(mouse)
LoadCharacter()
mouse.Button1Down:Connect(function()
if coolDown() then
m1Punch()
end
task.wait(.05)
end)
mouse.Button2Down:Connect(function()
if coolDown() then
task.spawn(m2Punch)
end
end)
end)
tool.Unequipped:Connect(function()
idle:Stop()
end)
function LoadCharacter()
character = player.Character or player.CharacterAdded:Wait()
humanoid = character.Humanoid
humanoidRootPart = character.HumanoidRootPart
m1 = humanoid.Animator:LoadAnimation(ReplicatedStorage.AnimEx.Fist["1"])
m2 = humanoid.Animator:LoadAnimation(ReplicatedStorage.AnimEx.Fist["2"])
m3 = humanoid.Animator:LoadAnimation(ReplicatedStorage.AnimEx.Fist["3"])
m4 = humanoid.Animator:LoadAnimation(ReplicatedStorage.AnimEx.Fist["4"])
m5 = humanoid.Animator:LoadAnimation(ReplicatedStorage.AnimEx.Fist["5"])
idle = humanoid.Animator:LoadAnimation(ReplicatedStorage.AnimEx.Fist.Idle)
heavyPunch = humanoid.Animator:LoadAnimation(ReplicatedStorage.AnimEx.Fist.M2)
Animations = {
m1;
m2;
m3;
m4;
m5;
heavyPunch;
}
idle:Play()
end