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

Get Mulitple Parts With The Same Name From A Folder?

Asked by 4 years ago

I want to make a object that when it gets close to a part with a certain name it plays an audio, the thing is that I want multiple parts to be around the map and have the object play the audio whenever it's around the part. I don't really know how to explain it well but basically I need some help with the getchildrenw which gets stuff from a folder in workspace. Here's the code. Thanks for viewing C:

while true do
    local partfind = game.Workspace.TestSound:GetChildren()
    local nfs = (script.Parent.Position - partfind.partSound.Position).magnitude
    ----The coding under this text is fine----
    if nfs <= 10 then
        script.Parent.Soundl1.PLFFF.Disabled = false
        script.Parent.Soundl1.PLFFF2.Disabled = true
        wait()
    end
    if nfs >= 9 then
        script.Parent.Soundl1.PLFFF.Disabled = true
        script.Parent.Soundl1.PLFFF2.Disabled = false
        wait()
    end
    wait()
end

1 answer

Log in to vote
0
Answered by 4 years ago

Have you maybe tried using loops to check the condition with each object with that name?

for _, v in pairs(partfind) do
    if v.Name == "partSound" then
        local nfs = (script.Parent.Position - v.Position).magnitude
        if nfs <= 10 then
        ...
    end
end

Hope this helped

0
I don't know if you'll see this message or reply but in the output box it says "Workspace.ROOF.soundPlay:5: bad argument #2 to '?' (Vector3 expected, got nil)" wafflesforall 4 — 4y
Ad

Answer this question