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

How to make this shorter?

if selecteditem.Value == "VIP Pass" then
		vipinfo.Visible = true
		murderinfo.Visible = false
		bucksinfo.Visible = false
		radioinfo.Visible = false
	elseif selecteditem.Value == "x3 Murderer Pass" then	
		vipinfo.Visible = false
		murderinfo.Visible = true
		bucksinfo.Visible = false
		radioinfo.Visible = false		
	elseif selecteditem.Value == "x2 Bucks Pass" then
		vipinfo.Visible = false
		murderinfo.Visible = false
		bucksinfo.Visible = true
		radioinfo.Visible = false		
	elseif selecteditem.Value == "Radio Pass" then
		vipinfo.Visible = false
		murderinfo.Visible = false
		bucksinfo.Visible = false
		radioinfo.Visible = true		
	end
end

How can I make this shorter? Everything is already defined, etc. I just need to make this shorter, cause I plan on adding extra stuff to it. Please help!!

2 comments

1

You have an issue where if they hold multiple ones then they will only see the first one they have.

0

i would make a function that disables all of them then enable the ones that you need

1 answer

✓ Accepted answer

For loops and tables will be handy for this kind of thing:

local tab = {}
tab["VIP Pass"] = vipinfo
tab["x3 Murderer Pass"] = murderinfo
tab["x2 Bucks Pass"] = bucksinfo
tab["Radio Pass"] = radioinfo

for i,v in pairs(tab) do
	if i == selecteditem.Value then
		v.Visible = true
	else
		v.Visible = false
	end
end

This could be even shorter if all these items are all children of the same parent, or if the names corresponded to the button names.

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