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 change the value of a bool value of multiple children?

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)`

3 comments

0

Sorry I messed up with the formatting.

0

Is there an error? I don't really see anything wrong at the moment.

0

Yes, it keeps saying "Stats is not a valid member of Model", but stats is a child of model.

1 answer

✓ Accepted answer
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!

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