I am sure there is a more efficient way of doing this I just don't know what it is. What I am trying to have happen is each time the player clicks the button to go through each one in order then start back over.
--// Required //-- local plot = script.Parent.Parent.Parent.BasePartLand local numMaterial = 1 local numColor = 1 --// Buttons //-- local material = script.Parent.Material.SurfaceGui.TextButton local color = script.Parent.Material.SurfaceGui.TextButton material.MouseButton1Click:connect(function() if numMaterial == 1 then plot.Material = Enum.Material.Cobblestone numMaterial = numMaterial + 1 elseif numMaterial == 2 then plot.Material = Enum.Material.Brick numMaterial = numMaterial + 1 elseif numMaterial == 3 then plot.Material = Enum.Material.DiamondPlate numMaterial = numMaterial + 1 elseif numMaterial == 4 then plot.Material = Enum.Material.Foil numMaterial = numMaterial + 1 elseif numMaterial == 5 then plot.Material = Enum.Material.Granite numMaterial = numMaterial + 1 elseif numMaterial == 6 then plot.Material = Enum.Material.Grass numMaterial = 1 end end)
First of all, you should use :Connect
instead of :connect
because it's deprecated.
Here is an improved code:
--// Required //-- local plot = script.Parent.Parent.Parent.BasePartLand local numMaterial = 1 local numColor = 1 local materials = { ["1"] = Enum.Material.Cobblestone; ["2"] = Enum.Material.Brick; ["3"] = Enum.Material.DiamondPlate; ["4"] = Enum.Material.Foil; ["5"] = Enum.Material.Granite; ["6"] = Enum.Material.Grass; } --// Buttons //-- local material = script.Parent.Material.SurfaceGui.TextButton local color = script.Parent.Material.SurfaceGui.TextButton material.MouseButton1Click:Connect(function() plot.Material = materials[tostring(numMaterial)] if numMaterial == 6 then numMaterial = 1 else numMaterial = numMaterial + 1 end end)