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

Get Mulitple Parts With The Same Name From A Folder?

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

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

1 comment

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)"

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