Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 5 years ago

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.

0
Then how do you expect us to help you Destroyer1234x 52 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago

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.

0
or just connect it to the parts directly without for loop of course GGRBXLuaGG 417 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

See this video over the CollectionService (This will help youwith the KillerPart)

0
I fixed the killer part NickIsANuke 217 — 5y

Answer this question