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

How can I shorten this with a table?

script.Parent.MouseButton1Click:connect(function(onClick)
   	script.Parent.BackgroundTransparency = 0.5
	script.Parent.Parent.Inv2.BackgroundTransparency = 0.7
	script.Parent.Parent.Inv3.BackgroundTransparency = 0.7	
	script.Parent.Parent.Inv4.BackgroundTransparency = 0.7
	script.Parent.Parent.Inv5.BackgroundTransparency = 0.7	
end)

I put this in another button, but when I click it it doesnt make Inv1 go back to 0.7

1 answer

✓ Accepted answer

I didn't test this code, but I think it should be something like this.

local p  = script.Parent.Parent 
local inv = { p.Inv2, p.Inv3, p.Inv4, p.Inv5 }
	
script.Parent.MouseButton1Click:connect(function(onClick)
	if script.Parent.BackgroundTransparency == 0.7 then
    	script.Parent.BackgroundTransparency = 0.5
		for index, value in ipairs(inv) do
    		index.BackgroundColor3 = 0.7
		end
	elseif script.Parent.BackgroundTransparency == 0.5 then
		script.Parent.BackgroundTransparency = 0.7
	end
end)

7 comments

0

I justeditted my answer with some more stuff that needs to be implement so yeah.

0

It's almost the same, just add the part I made inside the first if statement. I editted mine also.

0

thanks :)

0

it doesnt work :/

0

editted to another thing of why it isnt working

0

Well, try debugging with the print function. Check te values of p.Inv1 and find out if they're all connected well. Check if it sees the mouse click etc.

0

I have made one edit now. It works as is, just long in my eyes

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