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

when making a GetChildren script how to get 1 and change the transparency?

Asked by 5 years ago

model = game.Workspace.Model:GetChildren()

for i, v in pairs(model) do

v.Transparency = 0.5

i = model [1]

i.Transparency = 0.8

end

It kinda works, but it isn't the first one as stated in the brackets.

1 answer

Log in to vote
1
Answered by
CjayPlyz 643 Moderation Voter
5 years ago
Edited 5 years ago

This changes all the parts transparency inside the model to 0.8 :

local Model = workspace.Model

for i, Part in ipairs(Model:GetChildren()) do
    Part.Transparency = 0.8
end

This changes the first part's transparency in the model to 0.5 :

local Model = workspace.Model:GetChildren()
local Part = Model[1]
Part.Transparency = 0.5

This changes the first part's transparency in the model to 0.5 and 0.8 to everything else :

local Model = workspace.Model:GetChildren()

for i, Part in ipairs(Model) do
    if Part == Model[1] then
        Part.Transparency = 0.5
    else
        Part.Transparency = 0.8
    end
end

This changes all the parts transparency inside the model to 0.8 then changes the first part's transparency to 0.5 :

local Model = workspace.Model:GetChildren()

for i, Part in ipairs(Model) do
    Part.Transparency = 0.8
end

local Part = Model[1]
Part.Transparency = 0.5

You can change this :

local Part = Model[1]
Part.Transparency = 0.5

To this :

Model[1].Transparency = 0.5
0
Use ipairs(). GetChildren() returns an array and ipairs() is made specifically for arrays. DeceptiveCaster 3761 — 5y
0
oh... i didn't know that, thanks i'll edit it CjayPlyz 643 — 5y
Ad

Answer this question