Hello, I’m attempting to make a combat system for my game, but there’s one problem I’m currently having with it. Attacking a Single Target works, but upon making the character do a spin attack in a group of enemies only one enemy is effected resulting in the character getting pummeled to death. if someone could please shed some light on my problem I would much appreciate it I’ve Narrowed it down to being something within the following damage script
local Hit = Instance.new('Sound',hit.Parent.HumanoidRootPart)
Hit.SoundId = 'rbxassetid://636499038'
Hit.EmitterSize = 100
Hit.Volume = .2
local min = script.MinDMG.Value
local max = script.MaxDMG.Value
local char = hit.Parent
local hum = char:FindFirstChild("Humanoid")
if hum and char then
local Hurt = Instance.new("Animation")
Hurt.AnimationId = "rbxassetid://3369686028"
local facemoveleftTrack = hum:LoadAnimation(Hurt):Play()
hum:TakeDamage(math.random(min,max))
Hit:Play()
local Maker = script.creator
local SPD = script.Speed.Value
Maker.Parent = hum
script.Disabled = true
wait(SPD)
game.Debris:AddItem(Maker,SPD + 0.5)
script:Destroy()
end
if hum == nil then return end
end)
and I’m trying to accomplish this without the Player damaging themselves
Thank you Fixed Attacking self, but still need help dealing damage to more than one person at a time if multiple were hit
local Hit = Instance.new('Sound',hit.Parent.HumanoidRootPart)
Hit.SoundId = 'rbxassetid://636499038'
Hit.EmitterSize = 100
Hit.Volume = .2
local min = script.MinDMG.Value
local max = script.MaxDMG.Value
local char = hit.Parent
local hum = char:FindFirstChild("Humanoid")
if hum and char then
local Hurt = Instance.new("Animation")
if script.creator.Value == char.Name then
print("attempted to attack self")
else
print(char.Name)
Hurt.AnimationId = "rbxassetid://3369686028"
local facemoveleftTrack = hum:LoadAnimation(Hurt):Play()
hum:TakeDamage(math.random(min,max))
Hit:Play()
local Maker = script.creator:Clone()
local SPD = script.Speed.Value
Maker.Parent = hum
script.Disabled = true
wait(SPD)
game.Debris:AddItem(Maker,SPD + 0.5)
script:Destroy()
end
end
if hum == nil then return end
end)
By the looks of it seems like you using the touched event to detect the characters to damage, the touched event is not the best solution for this since it is not reliable. instead i recommend you use attachments and raycasting, if your not familiar with the aforementioned concepts then use this module : Raycast Hitbox 4.01: For all your melee needs!
I would use a table to store the NPCs/Players I hit and if they arn’t in the table deal damage and add them to the table, if they are in the table do nothing
basically something like this.
local HitTable = {}
Somthing.Touched:Connect(function(touched)
--check if they are player/npc
--check if they are in the table
--if not in table deal damage and add to table
--else ignore and dont do anything
end)