So I've been trying to get this attack of mine to do damage. The script creates a long cylinder as if its a "beam" and the goes through some loops to keep it centered with the characters HumanoidRootPart. I went and tried to add damage so that it would do about 5 damage every 1 second that it is touched but no damage script that I have tried has been working, this includes a damage script inside the part by itself. Could anyone help? The part of the script I want to add damage to is below:
Part in Script that creates and centers beam(I need a piece of code somewhere in here to do damage while the loops are going, I have already tried putting damage code inside the loops as well):
local Beam = game.ReplicatedStorage.Parts.Beam:Clone() Beam.CFrame = (player.Character.HumanoidRootPart.CFrame*CFrame.new(0, 0.5, -5)) *CFrame.Angles(0, math.rad(90), 0) Beam.Anchored = true Beam.CanCollide = false Beam.Parent = player.Character game.Debris:AddItem(Beam, 4) local increase = 0 for i = 1, 25 do increase = increase + 2.6 Charge.CFrame = player.Character.HumanoidRootPart.CFrame*CFrame.new(0, 0.5, -5) wait() Beam.CFrame = (player.Character.HumanoidRootPart.CFrame*CFrame.new(0, 0.5, -5 - increase)) *CFrame.Angles(0, math.rad(90), 0) Beam.Size = Beam.Size + Vector3.new(5, 0.2, 0.2) end for i = 1, 50 do wait() Charge.CFrame = player.Character.HumanoidRootPart.CFrame*CFrame.new(0, 0.5, -5) Beam.CFrame = (player.Character.HumanoidRootPart.CFrame*CFrame.new(0, 0.5, -5 - increase)) *CFrame.Angles(0, math.rad(90), 0) end
Im new and i dont really know but i suppose you could make a script (or maybe a localscript, idk) that says the following.
function onTouched(part) local h = part.Parent:findFirstChild("Humanoid") if h~=nil then h.Health = h.Health-5 wait(1) end end script.Parent.Touched:connect(onTouched)?
and duplicate it in every single part of the sword (example: handle)
im new so this script is pretty bad, just hope it works for you.