I made combat system and set the CD for punches but their speeds are different in the studio and in the game
Here is video with comparison:
Local script:
local event = game.ReplicatedStorage.Combat.CombatEvent
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local CS = game:GetService("CollectionService")
local InterfaceModule = require(game.ReplicatedStorage.Modules.Interface)
local checker = game.ReplicatedStorage.Checker
local ContentProvider = game:GetService("ContentProvider")
ContentProvider:PreloadAsync({game.ReplicatedStorage.Combat.Punch1Anim})
ContentProvider:PreloadAsync({game.ReplicatedStorage.Combat.Punch2Anim})
ContentProvider:PreloadAsync({game.ReplicatedStorage.Combat.HitAnim1})
ContentProvider:PreloadAsync({game.ReplicatedStorage.Combat.HitAnim2})
ContentProvider:PreloadAsync({game.ReplicatedStorage.Combat.HitAnim3})
local cd = false
local holded = false
game:GetService("UserInputService").InputBegan:Connect(function(Input,GPE)
if not GPE then
if Input.UserInputType == Enum.UserInputType.MouseButton1 then
local hrp = char:WaitForChild("HumanoidRootPart")
local hum = char:WaitForChild("Humanoid")
holded = true
task.spawn(function()
while holded == true do
local check = checker:InvokeServer(char,hum,"Combat")
if check == true and cd ~= true then
cd = true
delay(0.15,function()
cd = false
end)
event:FireServer()
end
task.wait(0.01)
end
end)
end
end
end)
game:GetService("UserInputService").InputEnded:Connect(function(Input,GPE)
if not GPE then
if Input.UserInputType == Enum.UserInputType.MouseButton1 then
holded = false
end
end
end)
Server script:
local combo = 0
local event = game.ReplicatedStorage.Combat.CombatEvent
local folder = game.ReplicatedStorage.Combat
local timeUntilComboResets = 2
local lastTimeClicked = tick()
local hitModule = require(game.ServerStorage.HitModule)
local function CombatFunc(player)
local char = player.Character or player.CharacterAdded:Wait()
local hrp = char:FindFirstChild("HumanoidRootPart")
local hum = char:FindFirstChild("Humanoid")
local cdTime = 0.3
local animation = hum:FindFirstChild("Animator"):LoadAnimation(folder.Punch1Anim)
local s = game.ReplicatedStorage.Combat.SwingSound:Clone()
local function ChangeCombo()
combo += 1
if combo == 1 then
s.TimePosition = 1.2
elseif combo == 2 then
s.TimePosition = 2.5
elseif combo == 3 then
s.TimePosition = 4
elseif combo == 4 then
s.TimePosition = 5.5
end
if combo == 1 or combo == 3 then
animation = hum:WaitForChild("Animator"):LoadAnimation(folder.Punch1Anim)
elseif combo == 2 or combo == 4 then
animation = hum:WaitForChild("Animator"):LoadAnimation(folder.Punch2Anim)
end
if combo >= 4 then
combo = 0
cdTime = 2
end
end
if tick() - lastTimeClicked >= timeUntilComboResets then --COMBO RESET
combo = 0
end
lastTimeClicked = tick()
ChangeCombo()
s.Parent = char
s:Play()
game.Debris:AddItem(s,1)
animation:Play()
char:SetAttribute("CombatCooldown",true)
delay(cdTime,function()
char:SetAttribute("CombatCooldown",false)
end)
coroutine.wrap(function()
hitModule.Attack(char,0,"Enable",8)
end)()
delay(0.3,function()
coroutine.wrap(function()
hitModule.Attack(char,0,"Disable")
end)()
hum.WalkSpeed = char:GetAttribute("WalkSpeedValue") or 16
hum.JumpHeight = char:GetAttribute("JumpHeightValue") or 7.2
end)
--Hitbox
animation:GetMarkerReachedSignal("hitbox"):Connect(function()
if combo == 0 then --FinalPunch
hitModule.Hitbox(0.1,Vector3.new(6,5,6),hrp.CFrame + hrp.CFrame.LookVector * 5,char,2.5,true,1.5,1,hrp.CFrame.LookVector * 30 + Vector3.new(0,30,0),0.1,nil,true,"Combat")
else
coroutine.wrap(function()
hitModule.Hitbox(0.1,Vector3.new(6,5,6),hrp.CFrame + hrp.CFrame.LookVector * 5,char,2.5,false,0,1,nil,0,nil,true,"Combat")
end)()
end
end)
player.Character:GetAttributeChangedSignal("Hitted"):Connect(function()
if player.Character:GetAttribute("Hitted") == true then
print("CombatHitted")
animation:Stop()
hum.WalkSpeed = char:GetAttribute("WalkSpeedValue") or 16
hum.JumpHeight = char:GetAttribute("JumpHeightValue") or 7.2
coroutine.wrap(function()
hitModule.Attack(char,0,"Disable")
end)()
CombatFunc():Disconnect()
end
end)
end
event.OnServerEvent:Connect(function(player)
CombatFunc(player)
end)
Thanks for help