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

more effective way to write this gui script?

Asked by 10 years ago
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

1 answer

Log in to vote
1
Answered by
Azarth 3141 Moderation Voter Community Moderator
10 years ago

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

pairs

arguments and parameters

0
This is really intense, I'm still starting off, and I don't really get how to use arguments and parameters and pairs etc, can you send me links on where I could learn all of this and I'll be able to understand this script better namelessassasin 30 — 10y
0
Also is it possible to write it without any arguments, would it be slower/longer? namelessassasin 30 — 10y
0
It's possible, but it's better just to pass it onto a separate function; learning how to use them will be very beneficial for you. Azarth 3141 — 10y
0
soo i learned abou the arguments and pairs and stuff and i edited my script and it works but the one problem is when i click the text button it turns yellow not orange, ive cheked the number for orange and everything but it turns yellow only and do i need this script in all of my buttons or just 1? namelessassasin 30 — 9y
0
You put the script in the frame with all the buttons, you don't put it in a button. Azarth 3141 — 9y
Ad

Answer this question