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

"Touched is not a valid member of model?" Touch script not working for two parts?

I made a script to pick 2 random parts out of a folder, then see if either are touched. My script is:

local num1 = math.random(1,3)
print("Num1 is"..num1)

local num2 = math.random(1,3)

repeat
	
	num2 = math.random(1,3)
	
until num2 ~= num1

print("Num2 is"..num2)

local paths = script.Parent.Paths

local deathPaths = Instance.new("Model")
deathPaths.Parent = script.Parent
deathPaths.Name = "DeathPaths"

paths:FindFirstChild(num1).Parent = deathPaths
paths:FindFirstChild(num2).Parent = deathPaths

function onTouched(part)
	local h = part.Parent:findFirstChild("Humanoid")
	if h~=nil then
		h.Health = 0
	end
end

print(deathPaths)
deathPaths.Touched:connect(onTouched)

It keeps on saying "Touched is not a valid member of model." How do I fix this to have the same functionality?

P.S. please don't try to change my whole script, all I want is help with getting the Touched event for two parts working.

1 comment

0

Then how do you expect us to help you

2 answers

You can't use Touched on a Model it has to be a Part

Instead use a for loop to loop through all the parts and connect their Touched to the function you want.

1 comment

0

or just connect it to the parts directly without for loop of course

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