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

more effective way to write this gui script?

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


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

5 comments

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

0

Also is it possible to write it without any arguments, would it be slower/longer?

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.

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?

0

You put the script in the frame with all the buttons, you don't put it in a button.

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