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

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

Asked by 5 years ago

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?

01local plr = game.Workspace:FindFirstChild(script.Parent.Parent.Name)
02print(plr)
03print(plr.Parent)
04 
05while true do
06    for i, v in pairs(game.Workspace:GetChildren()) do
07        local mag = (plr.HumanoidRootPart.Position - v.Position).magnitude
08        if mag < 20 then
09            break
10        end
11        end
12wait(0.01)
13end

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

1 answer

Log in to vote
3
Answered by
Fifkee 2017 Community Moderator Moderation Voter
5 years ago

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

1for i, v in pairs(workspace:GetChildren()) do
2    if (v:IsA('BasePart')) then -- if v Is A BasePart then..
3        --Base part is the base class for all parts, like meshparts, normal parts, wedges, and all that.
4    end
5end
0
Hmmm... I don't quite understand. FadedJayden_Dev 118 — 5y
0
Nvm. I think I get it. Thanks! FadedJayden_Dev 118 — 5y
Ad

Answer this question