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

How do you exclude something from i, v in pairs?

Soooooo.... I wanna create a new part whenever the players are close enough to a part in the workspace. It applies to all the parts in the workspace. When I used i,v in pairs, it won't work as there is Camera, Terrain in it. How do I exclude them out from i,v in pairs?

local plr = game.Workspace:FindFirstChild(script.Parent.Parent.Name)
print(plr)
print(plr.Parent)

while true do
	for i, v in pairs(game.Workspace:GetChildren()) do
		local mag = (plr.HumanoidRootPart.Position - v.Position).magnitude
		if mag < 20 then
			break
		end
		end
wait(0.01)
end

**Not the entire script. But it's the part that is being asked. :)

1 answer

✓ Accepted answer

Check if v is a basepart using the method :IsA().

for i, v in pairs(workspace:GetChildren()) do
	if (v:IsA('BasePart')) then -- if v Is A BasePart then..
		--Base part is the base class for all parts, like meshparts, normal parts, wedges, and all that.
	end
end

2 comments

0

Hmmm... I don't quite understand.

0

Nvm. I think I get it. Thanks!

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