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

How can I shorten this with a table?

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

Log in to vote
0
Answered by 10 years ago

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)
0
I justeditted my answer with some more stuff that needs to be implement so yeah. NinjoOnline 1146 — 10y
0
It's almost the same, just add the part I made inside the first if statement. I editted mine also. damagex443 325 — 10y
0
thanks :) NinjoOnline 1146 — 10y
0
it doesnt work :/ NinjoOnline 1146 — 10y
View all comments (3 more)
0
editted to another thing of why it isnt working NinjoOnline 1146 — 10y
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. damagex443 325 — 10y
0
I have made one edit now. It works as is, just long in my eyes NinjoOnline 1146 — 10y
Ad

Answer this question