So currently I have scripts that handle all of the light attacks and abilities, and have an individual code block for a damage event (e.g., projectile colliding with an enemy), but it ends early due to me disconnecting from an attack animation stopping to prevent duplicate effects later on. Would it be more efficient to tag a projectile or weapon with a “damage” tag and a damage value within, and have the server call a damage event every time an object with a damage tag connects, or would it flood the server with requests and be not worth my time.
-- this is what I am talking about
local animStop = loadAnim.KeyframeReached:Connect(function(keyframeReached)
if keyframeReached == "Attack" then
local hitbox = RS.ClassAttackEffects.Reaper.DeathWave:Clone()
hitbox.Parent = workspace
hitbox:PivotTo(CFrame.lookAt(HumanoidRootPart.Position, HumanoidRootPart.Position + HumanoidRootPart.CFrame.LookVector * 10))
local attachment = Instance.new("Attachment")
attachment.Parent = hitbox.PrimaryPart
attachment.Name = "Attachment0"
attachment.Orientation = Vector3.new(0,90,0)
attachment.Visible = true
local orientation = Instance.new("AlignOrientation")
orientation.Parent = hitbox.PrimaryPart
orientation.MaxTorque = "inf"
orientation.MaxAngularVelocity = "inf"
orientation.Attachment0 = attachment
orientation.RigidityEnabled = true
orientation.Mode = "OneAttachment"
orientation.CFrame = hitbox.PrimaryPart.CFrame
orientation.PrimaryAxis = hitbox.PrimaryPart.CFrame.LookVector
local force = Instance.new("LinearVelocity")
force.Parent = hitbox.PrimaryPart
force.VelocityConstraintMode = "Vector"
force.RelativeTo = "Attachment0"
force.Attachment0 = attachment
force.VectorVelocity = Vector3.new(100,0,0)
force.MaxForce = "inf"
hitbox.PrimaryPart.Touched:Connect(Blow)
end
end)
wait(loadAnim.Length)
canAttack = false
animStop:Disconnect()
debounce.Value = false
-- damage when connected
local modelsHit = {}
local function Blow(Hit)
if canAttack == true then
local parentModel = Hit.Parent
if parentModel then
-- check to see if this model has already been hit
if modelsHit[parentModel] then
return
end
-- log this model as hit
modelsHit[parentModel] = true
--[[damage = math.random(6*(level.Value * .5), 6*(level.Value * .75)) * dmgStat.Value
--local critchance = math.random(1,20)
--if critchance == 20 then
-- damage = damage * 2
--end]]--
damage = 10
if not Hit or not Hit.Parent then
return
end
local character = Hit.Parent
if character == Character then
return
end
local ignoreTag = character:FindFirstChildOfClass("BoolValue")
if ignoreTag then
if ignoreTag.Name == "Teammate" then
return
end
end
local humanoid = character:FindFirstChildOfClass("Humanoid")
if not humanoid or humanoid.Health == 0 then
return
end
humanoid:TakeDamage(damage)
wait(1)
modelsHit[parentModel] = false
end
end
end
help would (obviously) be appreciated
EDIT: nevermind, it is me calling canAttack to be false early, but still, is there a more efficient way to handle damage events?