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.
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.
See this video over the CollectionService (This will help youwith the KillerPart)