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

Finding all parts in a model?

Pretty much I'm checking if my arrow part is 4 studs distance with a "wall" part. The script works but for only 1 wall in the model, I put several parts and still just works with only 1. How could I do it so it works for ever part in the model?

local arrow = script.Parent

while wait() do
	wall = game.Workspace.Walls:GetChildren()
	for i = 1,#wall do
		if (wall[i].Position - arrow.Position).magnitude == 4 then
			arrow.Transparency = 0.5
		else
			arrow.Transparency = 0
		end
	end
end

Thanks :)

1 answer

I'm pretty sure you have to use in pairs when trying to find all children of a model.

local arrow = script.Parent

while wait() do
    wall = game.Workspace.Walls:GetChildren()
    for i,v in pairs(wall) do
        if (v.Position - arrow.Position).magnitude == 4 then -- shouldn't this be magnitude <= 4 then?
            arrow.Transparency = 0.5
        else
            arrow.Transparency = 0
        end
    end
end

Also, I haven't tested this script ;o

1 comment

0

That's not the only way of doing it...

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