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

How do you change the value of a bool value of multiple children?

Asked by 4 years ago

I have multiple NPC's with the same name in Workspace. They all have a bool value. How do I change the values of the bool value in all of the NPC's when I press a button?

`local Button = script.Parent

local function LeftClick()

local Npc1WS = game.Workspace:GetChildren()

for i,v in pairs(Npc1WS) do

    if v:IsA("Model") then

        v.Stats.Actions.Halt.Value = true

    end

end

end

Button.MouseButton1Click:Connect(LeftClick)`

0
Sorry I messed up with the formatting. VexTrexYT 28 — 4y
0
Is there an error? I don't really see anything wrong at the moment. ImTrev 344 — 4y
0
Yes, it keeps saying "Stats is not a valid member of Model", but stats is a child of model. VexTrexYT 28 — 4y

1 answer

Log in to vote
0
Answered by
ImTrev 344 Moderation Voter
4 years ago
local Button = script.Parent

local function LeftClick()

    local Npc1WS = game.Workspace:GetChildren()

    for i,v in pairs(Npc1WS) do
        if v:IsA("Model") then
            if v:FindFirstChild"Stats".Actions then -- should be good
                v.Stats.Actions.Halt.Value = true
            end
        end
    end
end

Button.MouseButton1Click:Connect(LeftClick)

If this doesn't work, please don't hesitate to contact me!

Ad

Answer this question