Hello, i'm currently working on a combat system and i'm having some trouble with how i should proceed.
I'm using ".Touched" for my hitbox. Now the main problem is that when two players or more are fighting each other, they will end up canceling each other out if they punch at the same time.
What i'm trying to do is that if the player gets hit and the other player in in the middle of a punch, the other players hitbox will get destroyed. Problem is that it is not working.
Here is the part of the script where it checks
Hitbox.Touched:Connect(function(Hit)
if Hitbox:IsA("BasePart") then
if not Hit:IsDescendantOf(Character) then
local enemy = Hit.Parent
local enemyHumanoid = enemy:FindFirstChild("Humanoid")
local enemyHumrp = enemy:FindFirstChild("HumanoidRootPart")
if enemyHumanoid and enemyHumrp then
local stunValue = Instance.new("BoolValue")
stunValue.Name = "Stunned"
stunValue.Parent = enemy
game.Debris:AddItem(stunValue,1.3)
spawn(function()
local enemyHitboxF = enemy:WaitForChild("CombatFolder",1)
pcall(function()
local enemyHitbox =
enemyHitboxF:WaitForChild("Hitbox",1)
if enemyHitbox then
enemyHitbox:Destroy()
end
end)
end)
Now i basically know the problem. The problem is that since i'm using spawn(function), it will continue on with the rest of the script. But if i don't use it the combat system will become glitchy as hell and damage the player multiple times in one punch.
Any suggestions on how i can improve it? Do i need to use something else than .Changed?
Thank you in advance :-)
