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

This script keeps outputting "Touched is not a valid member of tool"?

ball = script.Parent
damage = 10

r = game:service("RunService")

last_sound_time = r.Stepped:wait()

function onTouched(hit)

	local now = r.Stepped:wait()

	if (now - last_sound_time > .1) then
		ball.Boing:play()
		last_sound_time = now
	else
		return
	end

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

function tagHumanoid(humanoid)
	-- todo: make tag expire
	local tag = ball:findFirstChild("creator")
	if tag ~= nil then
		local new_tag = tag:clone()
		new_tag.Parent = humanoid
	end
end

function tagZombie(zombie)
	-- todo: make tag expire
	local tag = ball:findFirstChild("creator")
	if tag ~= nil then
		local new_tag = tag:clone()
		new_tag.Parent = zombie
	end
end


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

connection = ball.Touched:connect(onTouched)


t, s = r.Stepped:wait()
d = t + 5.0 - s
while t < d do
	t = r.Stepped:wait()
end

ball.Parent = nil

Line of error: connection = ball.Touched:connect(onTouched)

Not exactly sure whats wrong with it so if you can tell me how to fix it and explain why the error happens, that would be nice of you.

2 comments

0

Do you mean ball = script.Parent.Handle?

0

Nah it should be ball = script.Parent it is inside the tool not the handle

1 answer

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