script.Parent.MouseButton1Click:Connect(function() local Child = game.Workspace.GGG:GetChildren() Child.Anchored = false end)
I just watched a tutorial and wanted to try something new with :GetChildren(). This script is to set the two parts anchored property , inside a model "GGG" to false. This code is inside an local script. Please help.
When using :GetChildren() it returns a table, you can iterate through it using a i, v in pairs loop. You also have some other errors
Here is how your script should look:
local Player = game.Players.LocalPlayer local Mouse = Player:GetMouse() Mouse.Button1Down:Connect(function() local GC = game.Workspace.GGG:GetChildren() for i, v in pairs(GC) do v.Anchored = true end end)
Hope this helps!
You are trying to change a property of an array. (list of parts you got when getting all the children inside the model)
you would have to do it like this.
script.Parent.MouseButton1Click:Connect(function() local Child = game.Workspace.GGG:GetChildren() for i = 1,#Child do -- for i = starting number,Number of things in array do Child[i].Anchored = false end end)
This goes through all the children and changes their .Anchored to false. In case you didn't know this way the parts would only be unanchored for the player pressing the button and not for other players because it's a local script (local as in on their own game).
Mark XTOOTHLESX's answer because he got it correct first, but I am also making this just to show a different way of iterating through tables that I find to be easier to remember and easier to work with.
local Player = game.Players.LocalPlayer local Mouse = Player:GetMouse() Mouse.Button1Down:Connect(function() local GC = game.Workspace.GGG:GetChildren() table.foreach(GC, function(i,v) v.Anchored = true end) end)