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

Not sure if i'm using :GetChildren() correctly? Not a good scripter trying to see if it works

Asked by 5 years ago

Trying to do a script that when you click a button all the parts in the model "doors" become Transparent and CanCollide off, I dont want to have it so that every single individual part is listed in the script if possible, this is what i've thought will work but it dosent, any ideas?

function onClicked()
    game.Workspace.Door:GetChildren().Transparency = 1
    game.Workspace.Door:GetChildren().CanCollide = false
end

script.Parent.ClickDetector.MouseClick:connect(onClicked)
0
GetChildren is a table of everything so use a for loop to go through all the children and set transparency and collision 1 at a time. Launderer 343 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago

GetChildren() gives you a table meaning you would have to do something like:

for i = 1, #game.Workspace.Door:GetChildren() do
    game.Workspace.Door:GetChildren()[i].Transparency = 1
    game.Workspace.Door:GetChildren()[i].CanCollide =  false
end
Ad
Log in to vote
0
Answered by 5 years ago

If you put the script inside the Click Detector, you can do this :

script.Parent.MouseClick:connect(function()
    local door = game.Workspace.Door:GetChildren()
    door.CanCollide = false
    door.Transparency = 1
end)

Answer this question