I’m making a combat system and I’m coding on the hitbox right now. What I want to do is to make it less complicated or reduce lines of code on play animation and creating hitboxes so that I don’t need to copy and paste.
Local Script inside StarterCharacterScripts:
local replicatedstorage = game:GetService("ReplicatedStorage")
local runservice = game:GetService("RunService")
local mouse = game.Players.LocalPlayer:GetMouse()
local comboList = {
COMBO1 = replicatedstorage.ComboFolder.combo1
}
local combo = 1
local comboDuration = 0
local debounce = false
local combo1Track = script.Parent.Humanoid:LoadAnimation(comboList.COMBO1)
function comboHit(i)
replicatedstorage.HitboxEvent:FireServer(i)
end
runservice.Heartbeat:Connect(function ()
if combo < 4 then comboDuration = 0.5 end
if combo == 4 then comboDuration = 2 task.wait(1) combo = 1 end
end)
mouse.Button1Down:Connect(function ()
if debounce then return end
if not debounce then
combo += 1
comboHit(1)
debounce = true
task.wait(comboDuration)
debounce = false
end
end)
Server Script inside ServerScriptService
local replicatedstorage = game:GetService("ReplicatedStorage")
local Damage = require(replicatedstorage.Damage)
local debounce = false
local comboList = {
COMBO1 = replicatedstorage.ComboFolder.combo1
}
replicatedstorage.HitboxEvent.OnServerEvent:Connect(function (player, combo)
local combo1Track = player.Character.Humanoid:LoadAnimation(comboList.COMBO1)
if combo == 1 then
print("clicked")
combo1Track:Play()
combo1Track:GetMarkerReachedSignal("hitbox"):Connect(function ()
print("hitbox")
local hitbox = Instance.new("Part", game.Workspace)
hitbox.Transparency = 0.75
hitbox.Size = Vector3.new(6,4,2.5)
hitbox.Color = Color3.fromRGB(255, 66, 66)
hitbox.CFrame = player.Character.HumanoidRootPart.CFrame * CFrame.new(0,0,(((hitbox.Size.Z/2) + 1.5) * -1))
hitbox.Anchored = false
hitbox.Massless = true
hitbox.CanCollide = false
local weld = Instance.new("WeldConstraint", hitbox)
weld.Part0 = player.Character.HumanoidRootPart
weld.Part1 = hitbox
local overlapParams = OverlapParams.new()
overlapParams.FilterDescendantsInstances = {player.Character, hitbox}
local PartsInsideHitbox = workspace:GetPartsInPart(hitbox, overlapParams)
local function hitted(v)
if v.Parent:FindFirstChild("Humanoid") then
v.Parent:FindFirstChild("Humanoid"):TakeDamage(Damage.lightcombo)
end
end
for i, v in pairs(PartsInsideHitbox) do
if not debounce then
debounce = true
hitted(v)
end
end
debounce = false
hitbox:Destroy()
end)
combo1Track.Ended:Connect(function ()
print("success")
end)
end
end)
I was thinking about using table, but I don’t know how to use it for the combo.
For example:
table → combo1, combo2, combo3, combo4
When click. Fires from server.
First click = table[1]
Second click = table[2]
Third click = table[3]
Forth click = table[4]
back to first click