My hitbox touch event is really bad, the recently touch thing doesnt work it only acts like a debounce.
local function onRangeTouched(hit)
for _,v in pairs(CollectionService:GetTagged("Kill")) do
v.Touched:Connect(function(hit)
local humanoid = hit.Parent:FindFirstChild("Humanoid") :: Humanoid
if not humanoid then
return
end
local character = hit.Parent
local player = Players:GetPlayerFromCharacter(character)
local killer = Players:GetPlayerFromCharacter(v.Parent.Parent)
if recentlyDamagedCharacters[character] then
return
end
if ReplicatedStorage.Game:GetAttribute("Text") == Settings.RunnerWinStatus then
return
end
if not player then return end
local Damage = v:GetAttribute("Damage") or 0
if player.Team and player.Team == Settings.Green then
task.spawn(function()
recentlyDamagedCharacters[character] = true
Damage += Settings.RangeDamage
humanoid:TakeDamage(Settings.RangeDamage)
local newBlood = Blood:Clone()
for _, instance in pairs(newBlood:GetChildren()) do
local root = player.Character.HumanoidRootPart
if instance:IsA("ParticleEmitter") then
instance = instance :: ParticleEmitter
instance.Parent = root
instance:Emit(instance:GetAttribute("EmitCount"))
end
if instance:IsA("Sound") then
instance = instance :: Sound
PlaySound(instance, root)
end
end
wait(Settings.RangeCooldown)
recentlyDamagedCharacters[character] = nil
end)
end
if humanoid.Health ~= 0 or humanoid:FindFirstChildOfClass("ObjectValue") then
return
end
local ObjectValue = Instance.new("ObjectValue")
ObjectValue.Value = killer
ObjectValue.Parent = humanoid
local playerData = Data:GetData(player)
local killerData = Data:GetData(killer)
local killEffect = killerData.Cosmetics.KillEffect
killerData.Statistics.Kills += 1
killerData.Statistics.Bolts += Settings.SeekerKillBolts
playerData.Statistics.Deaths += 1
if not killEffect then
return
end
-- kill effect
for _, effect in pairs(Assets.Effects.Kill:GetChildren()) do
if tostring(effect) ~= killEffect then
continue
end
local effect = Assets.Effects.Kill[killEffect]:Clone()
local root = player.Character.HumanoidRootPart
for _, instance: Instance? in pairs(effect:GetChildren()) do
if instance:IsA("ParticleEmitter") then
instance = instance :: ParticleEmitter
instance.Parent = root
instance:Emit(instance:GetAttribute("EmitCount"))
end
if instance:IsA("Sound") then
instance = instance :: Sound
PlaySound(instance, root)
end
end
end
end)
end
end
How do I clean this up and fix the recently damaged table?