Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

changing only named parts help?

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

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)

2 comments

0

how would this fit into the script? (Never used iPairs before)

0

If you use the search bar you'd find a good answer.

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