I'm very new to scripting, and there's this old flamethrower from back in 2006 that I wanted to add in my game. I looked up some stuff on how to make hopperbin tools work as normal tools. (basically just made the hopperbin a tool that doesn't require a handle and replaced the scripts with local scripts) Everything works fine up until the damage part of the script comes up. When I launch a test server, I get the error "Touched is not a valid member of Tool" on the line of code "connection = fire.Touched:connect(onTouched)". The thing can shoot, but can't apply damage. Anyway I can fix this?

fire = script.Parent
damage = 2

function onTouched(hit)
	local humanoid = hit.Parent:findFirstChild("Humanoid")
	if humanoid~=nil then
		tagHumanoid(humanoid)
		humanoid.Health = humanoid.Health - damage
		wait(2)
		untagHumanoid(humanoid)
		connection:disconnect()
	else
		damage = damage / 2
		if damage < 0.1 then
			connection:disconnect()
		end
	end
end

function tagHumanoid(humanoid)
	
	local tag = fire:findFirstChild("creator")
	if tag ~= nil then
		local new_tag = tag:clone()
		new_tag.Parent = humanoid
	end
end


function untagHumanoid(humanoid)
	if humanoid ~= nil then
		local tag = humanoid:findFirstChild("creator")
		if tag ~= nil then
			tag.Parent = nil
		end
	end
end

--Error here
connection = fire.Touched:connect(onTouched)



r = game:service("RunService")
t, s = r.Stepped:wait()
d = t + 2.0 - s
madeGrey = false
while t < d do
	t = r.Stepped:wait()
	if madeGrey == false and d-t < .7 then
		madeGrey = true
		fire.BrickColor = BrickColor.new(.4,.4,.4)
	end
end

fire.Parent = nil

5 comments

0

Tools don't have the touched event in their class. Try using a part thats a child of your tool.

0

Wait, 'fire' isn't a tool right? It's the flames/part?

0

Yeeh, 'fire' isn't a tool in itself. This is the tool if you wanted to check it out: https://www.roblox.com/library/2275225984/FlameThrower

0

Lmao it literally says Touched is not a valid member of Tool. And youre calling fire.Touched(func) come on man lol..

0

This site is for helping users with self made code, not to fix free models.