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

How do I get every single part in workspace?

Asked by 6 years ago

I was thinking of getting all the parts with a class name of Part, meshpart, wedge etc.Maybe even tracking all the descendants. Also thinking of adding for loops into all the models, but that sounds a little too troublesome if you ask me. Is there any easier, more efficient ways for me to get every single part in the workspace? Maybe something detecting the mouse target and automatically turning the target filter to them

1 answer

Log in to vote
1
Answered by 6 years ago

To return every child of workspace, you use the GetChildren method.

for _,v in pairs(workspace:GetChildren()) do
    if v:IsA("BasePart") then
        print(v.Name)
    end
end

Assuming I understood the final portion of your question, you would use the GetMouse method in a LocalScript.

local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
local tar = mouse.Target

mouse.Move:connect(function()
    print(tar)
end)
0
Your second code block would not work because 'tar' is a fixed value. Set 'tar' inside the callback so it updates every time the callback runs. TheDeadlyPanther 2460 — 6y
Ad

Answer this question