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

game.ServerStorage.Crates.RobloxImage Not Showing Help?

No errors in output for some reason this script is supposed to say when player gets to 100% show slots which it's a 5 block GUI and then the slots are what goes in the 5 blocks but this all works but then when it's told with math.random this is incomplete this is only for slot1 but the robloximage is supposed to be put in slot1 please help?

plr = game.Players.LocalPlayer
script.Parent.MouseButton1Click:connect(function()
	local check1 = plr:WaitForChild("leaderstats")
	if check1 then
		local Percent = check1:WaitForChild("Percent")
		if Percent then
			Percent.Value = Percent.Value + 1
			 local Amount = plr.PlayerGui.CaseClicker.CaseClicker2.Search
			Amount.Text = "Search For Crates : "..tostring(Percent.Value)..tostring("%")
			if Percent.Value == 100 then
				Percent.Value = 0
				plr.PlayerGui.Chooser.Slots.Visible = true
				local crates = game.ServerStorage.Crates
				local commonclone = crates.Common:Clone()
				local uncommonclone = crates.Uncommon:Clone()
				local Rareclone = crates.Rare:Clone()
				local Ultrarareclone = crates.Ultrarare:Clone()
				local Epicclone = crates.Epic:Clone()
				local Legendaryclone = crates.Legendary:Clone()
				local clones = {commonclone,uncommonclone,Rareclone,Ultrarareclone,Epicclone,Legendaryclone}
				local choice1 = math.random(1,6)
				if choice1 == 1 then
					commonclone.Parent = plr.StarterGui.Chooser.Slots.Slot1
					if choice1 == 2 then
						uncommonclone.Parent = plr.StarterGui.Chooser.Slots.Slot1
						if choice1 == 3 then
							Rareclone.Parent = plr.StarterGui.Chooser.Slots.Slot1
							if choice1 ==4 then
								Ultrarareclone.Parent = plr.StarterGui.Chooser.Slots.Slot1
								if choice1 == 5 then
									Epicclone.Parent = plr.StarterGui.Chooser.Slots.Slot1
									if choice1 == 6 then
										Legendaryclone.Parent = plr.StarterGui.Chooser.Slots.Slot1
									end
								end
							end
						end
					end
				
				end
			end
		end
	end
	wait(1)
end)

1 answer

✓ Accepted answer

Notice how your ifs are "nested"?

You will only check if choice1 == 6 when it has already been the case that choice1 == 5 and choice1 == 4 and choice1 == 3...

You're only executing all of the other checks when choice1 == 1.

Use elseif:

-- for example
if choice == 1 then
	common.Parent = gui
elseif choice == 2 then
	uncommon.Parent = gui
elseif choice == 3 then
	rare.Parent = gui
end

Of course, you don't need this giant condition. If you find yourself counting in your code (as you are with 1, 2, 3, and as it seems you might with choice1, choice2...) it means you should use arrays instead.

You have a clones array but you don't use it. Lines 21 to 40 can be replaced with these two lines:

local choice = clones[math.random(#choice)]
choice.Parent = plr.StarterGui.Chooser.Slots.Slot1

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