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

changing only named parts help?

Asked by
NotSoNorm 777 Moderation Voter
8 years ago

So I have a script that changes the parts to neon if they aren't (sorta broken as is) I was wonder, how can I only change the parts with the name "Colorfull"

function onClicked()
local GetBoat = game.Players.LocalPlayer.Character
    local colorfulls = GetBoat.NormalBoat:GetChildren("Colorfull")
local boot = GetBoat.NormalBoat
                if boot.Colorfull.Material == "Neon" then
                    print("If2done")
                    for i = 1, #colorfulls do
                        colorfulls[i].Material = "Plastic"
                    end
                    script.Parent.booton.TextColor3 = Color3.new(255,255,255)
                            else
                    for i = 1, #colorfulls do
                            colorfulls[i].Material = "Neon"
                    end
                 script.Parent.booton.TextColor3 = Color3.new(255,0,0)
            end
        end
script.Parent.booton.MouseButton1Click:connect(onClicked)

1 answer

Log in to vote
0
Answered by
woodengop 1134 Moderation Voter
8 years ago

Use the Pairs function, and the GetChildren() method is a read only table of the parent's children.


local colorFull = GetBoat.NormalBoat:GetChildren()

for i,v in pairs(colorFull) do -- the i,v and be renamed f.y.i
    -- settings
end

Edited

function onClicked()
local GetBoat = game.Players.LocalPlayer.Character
local colorfulls = GetBoat.NormalBoat:GetChildren()
local boot = GetBoat.NormalBoat
for i,v in pairs(colorfulls) do
    if v.Name=="NamHere" then
        print("If2done")
        for i = 1, #colorfulls do
                colorfulls[i].Material = "Plastic"
        end
    else
        script.Parent.booton.TextColor3 = Color3.new(255,255,255)
        for i = 1, #colorfulls do
            colorfulls[i].Material = "Neon"
         end
            script.Parent.booton.TextColor3 = Color3.new(255,0,0)
        end
    end
end
script.Parent.booton.MouseButton1Click:connect(onClicked)

0
how would this fit into the script? (Never used iPairs before) NotSoNorm 777 — 8y
0
If you use the search bar you'd find a good answer. woodengop 1134 — 8y
Ad

Answer this question