function turnOrange() script.Parent.TextColor3 = Color3.new(255, 162, 0) script.Parent.Parent.CustomClass1.TextColor3 = Color3.new(255, 255, 255) script.Parent.Parent.CustomClass2.TextColor3 = Color3.new(255, 255, 255) script.Parent.Parent.CustomClass3.TextColor3 = Color3.new(255, 255, 255) script.Parent.Parent.CustomClass4.TextColor3 = Color3.new(255, 255, 255) end script.Parent.MouseButton1Down:connect(turnOrange)
rather than putting this in all my buttons and changing the numbers, is there a better way to write this script so that when a player clicks ona certain textbutton the textbutton will turn orange while the others stay white? also its suppose to turn orange but it keeps turning yello any ideas..the color for orange is 255, 162, 0 but it changes to yellow
local last = nil local function turnOrange(new) if last ~= nil then -- If one has already been changed then if new.Name ~= last.Name then -- if the last one clicked wasn't the same one you just click then new.TextColor3 = Color3.new(255, 162, 0) last.TextColor3 = Color3.new(1,1,1) end else -- If one hasn't been clicked yet, then there's no need to make anything white yet. new.TextColor3 = Color3.new(255, 162, 0) end -- keep track of the last button clicked; I'd rather do it this way, than a for loop. last = new end for i,v in pairs(script.Parent:GetChildren()) do -- Index all your TextButtons if v:IsA("TextButton") then v.MouseButton1Click:connect(functon() turnOrange(v) end) end end