Hello developers, my problem is a hitbox bug.Hitboxes in my game are desks that collide between each other causing damage. Here is the script I use normally:
projectile.Touched:Connect(function(hit)
local humanoid, hitPlayer = getHumanoidAndPlayerFromPart(hit)
if humanoid and hitPlayer ~= playerWhoShot and not hitHumanoids[humanoid] then
-- Наносим урон, если это не стрелявший игрок
if humanoid.Health > 0 then
local dam = damage+(zaryad*3)+A
if A <= 20 then
dam = damage+(zaryad*3)+(A)
elseif A > 20 and A <= 50 then
dam = damage+(zaryad*3)+(A*1.5)
elseif A > 50 then
dam = damage+(zaryad*3)+(A*1.75)
end
if hit.Parent.Humanoid:FindFirstChild("Shield") then
if hit.Parent.Humanoid.Shield.Value <= 0 then
hit.Parent.Humanoid:TakeDamage(dam)
else
if hit.Parent.Humanoid.Shield.Value <= dam then
hit.Parent.Humanoid:TakeDamage(dam-hit.Parent.Humanoid.Shield.Value)
hit.Parent.Humanoid.Shield.Value = 0
else
hit.Parent.Humanoid.Shield.Value -= dam
end
end
else
hit.Parent.Humanoid:TakeDamage(dam)
end
hitHumanoids[humanoid] = true
zaryad += 1
print(zaryad)
delay(10,function()
zaryad -= 1
end)
loadDamageGui(hit,dam)
local blood = game.ServerStorage.Blood.Attachment:Clone()
blood.Parent = humanoid.Parent.HumanoidRootPart
blood.ParticleEmitter:Emit(1)
game.Debris:AddItem(blood,1)
end
end
end)
or
local function getPlayerFromPart(part)
local humanoid = part:FindFirstChildWhichIsA("Humanoid") or part.Parent:FindFirstChildWhichIsA("Humanoid")
if humanoid then
return game.Players:GetPlayerFromCharacter(humanoid.Parent)
end
return nil
end
if hit.Parent:FindFirstChild("Humanoid") and hasDamaged then
if hit.Parent.Humanoid:FindFirstChild("Shield") then
if hit.Parent.Humanoid.Shield.Value <= 0 then
hit.Parent.Humanoid:TakeDamage(dam)
else
if hit.Parent.Humanoid.Shield.Value <= dam then
hit.Parent.Humanoid:TakeDamage(dam-hit.Parent.Humanoid.Shield.Value)
hit.Parent.Humanoid.Shield.Value = 0
else
hit.Parent.Humanoid.Shield.Value -= dam
end
end
else
hit.Parent.Humanoid:TakeDamage(dam)
end
All hitboxes and projectiles have the tag perra
The error is that the first projectile is destroyed if another player applies a second type of attack with a different hitbox, as far as I was able to verify this is not related to CanTouch CanColide and similar settings, as spavn hitbox in the workspace separately solves the problem, but in the case of a hitbox appears on the script occurs some error that destroys the first projectile.
Please help me with this problem. I think it may be something to do with scripts or with roblox studio directly