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

Legendary Crate Only it wont change to any other crate Help?

Like when I get to 5% it gives me my opening which then shows me legendary crates all the time I tried it like 6 times and got legendary crate I'm thinking it's because the math.random to the #of clones I think because the number of clones is 6 and I have else if c == 6 then legendary not sure please Help?

 crates = game.ServerStorage.Crates
 commonclone = crates.Common:Clone()
uncommonclone = crates.Uncommon:Clone()
Rareclone = crates.Rare:Clone()
 Ultrarareclone = crates.Ultrarare:Clone()
 Epicclone = crates.Epic:Clone()
 Legendaryclone = crates.Legendary:Clone()
clones = {commonclone,uncommonclone,Rareclone,Ultrarareclone,Epicclone,Legendaryclone}
c = clones[math.random(#clones)]
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 == 5 then
				Percent.Value = 0
				plr.PlayerGui.Chooser.Slots.Visible = true
				if c == 1 then
					commonclone.Parent = plr.PlayerGui.Chooser.Slots.Slot1
					 else if c == 2 then
						uncommonclone.Parent = plr.PlayerGui.Chooser.Slots.Slot1
						else if c == 3 then
							Rareclone.Parent = plr.PlayerGui.Chooser.Slots.Slot1
							else if c ==4 then
								Ultrarareclone.Parent = plr.PlayerGui.Chooser.Slots.Slot1
								else if c == 5 then
									Epicclone.Parent = plr.PlayerGui.Chooser.Slots.Slot1
									else if c == 6 then
										Legendaryclone.Parent = plr.PlayerGui.Chooser.Slots.Slot1
									end
								end
							end
						end
					end
				end
				c.Parent = plr.PlayerGui.Chooser.Slots.Slot1
			end
		end
	end
	wait(1)
end)

1 comment

0

math.random is based off a 'seed,' meaning the starting won't change, use math.randomseed to change the seed

1 answer

There are a lot of things that need to be looked at here 1st else if and elseif are not the same ting. e.g.:-

local a = 0
function run()
	print('running')
	if a == 1 then
		print('test 1 num ', a)
	else if a == 3 then
			print('test 2 num ', a)
		end
		print('????')
	end
	a = a + 1
end

function run2()
	print('running')
	if a == 1 then
		print('test 1 num ', a)
	elseif a == 3 then
		print('test 2 num ', a)
	end
	a = a + 1
end

for i=0, 4 do
	run()
end
a = 0
print()
for i=0, 4 do
	run2()
end

The second problem is that you do not change local c = clones[math.random(#clones)] this will mean the same value is used each click. An alternative method would be:-

if math.random(1, 100) <= 5 then -- this should be close to 5%
end

Lastly you make all of the clones at the top of the script then when the button is clicked you re-parent then. This will mean if the button is clicked again you will be using the same box or nil of the box does not exist which will error.

I hope this will help you, If you struggle to resolve this please update the code again.

1 comment

0

You missed an else if on line 6 of your script :3

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