Hello developers and scripters!
Problem: Both attacks are linked to the same attacking body part
I am trying to make a barrage attack for my little fun creation. The problem is that, for my attacks, punch and barrage, I can only set the attack to one body part (unless you can fix that). As in, the punch is set to the Right Arm and the barrage is, too.
I was thinking on adding two invisible parts on the hands of the player, but I don’t know how to do that (welding a part to the arm).
Since I am not stuck to only 2 hours of creating this combat system, like I did here: First Combat System in Two Hours! (I gave the game file here)
I can spend as much time as I want because it’s not a 2 hour challenge. So I added effects (also the first time)
The updated script (see the link and download the game file to see the original):
local char = script.Parent
local animIsPlaying = false
local combatParts = {
Punch = char['Right Arm'],
Uppercut = char['Left Arm'],
Kick = char['Right Leg'],
Barrage = char['Right Arm']
}
local damage = {
Punch = 10,
Uppercut = 15,
Kick = 22,
Barrage = 3 -- Per hit
}
local cooldown = {
Punch = 0.5,
Uppercut = 3,
Kick = 5,
Barrage = 10
}
local cooldownActive = {
Punch = false,
Uppercut = false,
Kick = false,
Barrage = false
}
local hum = char:WaitForChild('Humanoid')
local ev = char.Attack
local ev2 = char.OnCooldown
ev.OnServerEvent:Connect(function(plr, attack)
if not animIsPlaying then
local anim = hum.Animator:LoadAnimation(script[attack])
local attacks = 0
local barrageEffects = {
Blows = nil,
Light = nil
}
if not cooldownActive[attack] then
anim.Priority = Enum.AnimationPriority.Action
anim:Play()
print('Attack: '.. tostring(attack))
cooldownActive[attack] = true
ev2:FireClient(plr, attack, cooldownActive[attack])
-- Below is just speeds for specific attacks
if attack == 'Kick' then
hum.WalkSpeed = 0
elseif attack == 'Barrage' then
hum.WalkSpeed = 3
end
animIsPlaying = true
-- Below, hum2 is the target
if attack == 'Barrage' then
combatParts[attack].Touched:Connect(function(hit)
local hum2 = hit.Parent:FindFirstChild('Humanoid')
if hum2 then
if animIsPlaying and not (hit.Parent:FindFirstChild('Torso'):FindFirstChild('Blows') or hit.Parent:FindFirstChild('Torso'):FindFirstChild('Light')) then
for i, v in pairs(workspace.Target:GetChildren()) do
local newV = v:Clone()
newV.Parent = hit.Parent.Torso
newV.Enabled = true
barrageEffects[v.Name] = newV
print('Added effects to target')
end
elseif animIsPlaying then
barrageEffects.Blows = hit.Parent.Torso.Blows
barrageEffects.Light = hit.Parent.Torso.Light
end
if attacks < 20 and animIsPlaying then
attacks += 1
hum2:TakeDamage(damage[attack])
end
end
end)
else
wait(anim.Length / 2) -- Wait until the attacking body part is actually in motion
combatParts[attack].Touched:Connect(function(hit)
local hum2 = hit.Parent:FindFirstChild('Humanoid')
if hum2 then
if attacks < 1 and animIsPlaying then
attacks += 1
hum2:TakeDamage(damage[attack])
end
end
end)
end
anim.Stopped:Wait()
if barrageEffects.Blows then -- No need of adding "~= nil" after
print('Destroyed barrage effects')
barrageEffects.Blows:Destroy()
barrageEffects.Light:Destroy()
end
hum.WalkSpeed = 20
animIsPlaying = false
wait(cooldown[attack])
cooldownActive[attack] = false
ev2:FireClient(plr, attack, cooldownActive[attack])
end
end
end)
Thank you in advance! All help appreciated!