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

Fireball won't do damage?

I'vebeen trying to create a fireball that damages other players when they come into contact with it. The problem is, that for some reason the damage script doesn't work, and I keep getting the error "Touched isn't a valid member of local script." I've tried moving around where to clone the script in the fireball's code but it just doesn't want to work for some reason. It would really help if someone could tell me how to fix this. Fireball Code:

local variable cooldown = 1
function shoot()
	if cooldown == 1 then 
		print("Works")
		cooldown = 0
	local fireball = Instance.new("Part") --Creates a new Part Called Fireball
	fireball.TopSurface = "Smooth"
	fireball.BottomSurface = "Smooth"
	fireball.BrickColor = BrickColor.new("Really red")
	fireball.Transparency = 0.3
	fireball.Size = Vector3.new(2, 2, 2)
	fireball.CFrame = game.Players.LocalPlayer.Character.Torso.CFrame *CFrame.new(0,0,-5) --Where the Fireball Starts
	fireball.Parent = game.Workspace
	fireball.Anchored = true --Anchors Fireball
	fireball.CanCollide = false
	local damage = script.Damage:clone() --Clones the damage script
	damage.Parent = fireball
	damage.Disabled = false --Enables the damage script
	local mesh = Instance.new("SpecialMesh", fireball) --Adds a mesh to the Fireball
	mesh.MeshType = "Sphere" --Makes the mesh a sphere
	local fire = Instance.new("Fire", fireball) --Adds fire to the fireball
	fire.Heat = 8
	fire.Size = 20
	local bv = Instance.new("BodyVelocity") --creates velocity for the fireball
	bv.maxForce = Vector3.new(math.huge,math.huge,math.huge) --MaxForce is so high almost as to be unlimited
	bv.velocity = game.Players.LocalPlayer.Character.Torso.CFrame.lookVector*80
		for i = 1,13 do
		fireball.Mesh.Scale = fireball.Mesh.Scale +Vector3.new(0.5,0.5,0.5) --Makes the fireball grow
		wait()
	end
	bv.Parent = fireball --Adds the velocity to the fireball
	fireball.Anchored = false
	wait(3)
	cooldown = 1
	fireball:Destroy()
	end
end
script.Parent.Activated:connect(shoot)

And here's the damage code:

local enabled = false

function Damage(hit)
	local h = hit.Parent:FindFirstChild("Humanoid")
	if h and not enabled then
		enabled = true
		for i = 1,20 do
			h.Health = h.Health - 3
			wait(1/15)
		end
	end
	enabled = false
end
script.Parent.Touched:connect(Damage)

4 comments

0

i think Touched doesnt work with CanCollide off. try turning it on then trying it and get back to me

0

Mind showing us what the tool looks like in the Explorer menu?

0

Bubbaman, touched does work with CanCollide off :P

0

Try changing the local script inside the fireball to a regular script.

1 answer

✓ Accepted answer

I've copied your script and found the problem, I guess. When I activated the tool the first time, I got the same error. Now what was the problem? This was the problem! I (and most likely you too) forgot to disable the script. This causes that error to show up, but shouldn't affect the cloned script. After that and after naming the script inside the LocalScript "Damage", it all worked perfectly fine and looked great. Good work! So your problem was most likely just that you didn't disable the "Damage" script AND forgot to add a Handle. A tool has the property RequireHandle, which disables the event .Activated IF there is no Handle. So you may just set this property to false or add a Handle.

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