Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why Won't Damage Code Work Inside This Attack's Script?

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

4 comments

0

How would your beam know it's touching a player if it's CanCollide is false? By damage code, have you tried player.Character.Humanoid:TakeDamage(5)? I know it hurts the caster.

0

Maybe use a coroutine? It might not help but it's worth a try.

0

I have tried making it do damage even to the caster and it didn't work, also, I have other attacks that work fine with the damage code and have cancollide set to false. I can't do a coroutine because it creates a new beam everytime. Also, can't use ray casting because that isn't the look that I'm going for with this attack.

1 answer

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.

1 comment

0

I appreciate the effort, but like i said I have already tried this. Also, i'm not making a sword, it is a beam attack.

This discussion is preserved as it was. New answers, comments, and votes are closed.