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

How to make a local value equal multiple parts?

Asked by 5 years ago

So I have

local mousetarget = 

What would I put to the right of the equal sign, for it to be every brick in workspace that has a bool value in it named "Purchase" that is true?

2 answers

Log in to vote
0
Answered by
iladoga 129
5 years ago

Its quite simple, you just have to iiterate through every object in workspace. and check if it have the value.

for i,v in pairs(game.Workspace:GetChildren()) do
    if v:FindFirstChild("Purchased") ~= nil then
        localMouseTarget = v
    end
end

"v" would be an object, this might not work but it should, if it doesn't try making a table and inserting v into a table.

0
thx barrettr500 53 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

There is nothing for that, there is a loop though...

for _, v in pairs(workspace:GetChildren()) do
    if v:FindFirstChild("Purchase") then
        if v.Purchase.Value == true then
            local mousetarget = v
            print(mousetarget.Name)
        end
    end
end

looping and finding purchased through all the parts then finding if its value is true then making the "mousetarget" the part...

Answer this question