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

UNANSWERED Weapon Class Gui Help?

I made this weapon class gui but i want to add to it that classes 2- 6 wont be able to be clicked unles they have the level needed..meaning that what ever there level is in leaderboard it will unlock.. like say class 2 needs level 4 to be able to be clicked in the frame they are all name class 1,class2, class 3 and so on

Here it is


player = script.Parent.Parent.Parent 
backpack = player.Backpack 

function chooseClass(class)
	for i, v in pairs(backpack:GetChildren()) do v:remove() end
	for i, v in pairs(class:GetChildren()) do
		if v:IsA("Tool") then
			v:clone().Parent = backpack
		elseif v:IsA("HopperBin") then
			v:clone().Parent = backpack
		end
	end
	script.Parent.Main.Visible = false --no new class for a little bit
	wait(600000)
	script.Parent.Main.Visible = true --allow to pick a different class
end

for i, v in pairs(script.Parent.Main:GetChildren()) do
	v.MouseButton1Up:connect(function () chooseClass(v) end)
end

1 comment

0

This script is very strange... I only don't understand what's happening in your generic loop on line 18, I don't think that would even work... All you'll need to do is check where the level is stored to view the value and if it's not = to it, do nothing

2 answers

✓ Accepted answer

Between lines 4 and 5 (or in line 19 before you call chooseClass(v)) you need to check the local player's value (probably in player.leaderstats .Rank.Value) for the proper value.

You will probably want to set up a table to keep track of the level requirements, like this:

levelRequirements = {1, 2, 4, 10, 20, 100} --level required for class1, class2, etc

Between lines 4 and 5 put this:

	local classNum = tonumber(class.Name:sub(6))
	if player.leaderstats.Rank.Value < levelRequirements[classNum] then
		--do something to show the player that they don't have the level for this class
		return
	end

(Don't forget to change player.leaderstats.Rank.Value to reflect whatever you've got setup in your game)

2 comments

0

thanks but how do i set up the table and make it work out with the gui?

0

Use the 'levelRequirements' line; put it anywhere before line 4 (line 4 in your original script)

It's because you're making it wait 600000 SECONDS?! (or almost 7 days).. In other words you pause the script (thread, more precisely) for that much time.

Anyway, why do you need wait 7 days?!

If you really have a reason to, here are a bunch of ways to fix it

1. Use a separate thread using coroutines

-- Examples
function chooseClass(class)
	coroutine.resume(coroutine.create(function() -- THIS
		-- ............
	end))
end

function chooseClass(class)
	coroutine.wrap(function() -- THIS
		-- ............
	end)()
end

2. Use a separate thread using the spawn function

-- Examples
function chooseClass(class)
	spawn(function() -- THIS
		-- ............
	end)
end

-- ... OR
for i, v in pairs(script.Parent.Main:GetChildren()) do
	v.MouseButton1Up:connect(function ()
		spawn(function() -- THIS
			chooseClass(v)
		end)
	end)
end

3. Use the delay function

Instead of..

script.Parent.Main.Visible = true
wait(600000)

Do..

delay(600000, function()
	script.Parent.Main.Visible = true
end)

2 comments

0

dude this still wont work with the type im talking about.. i mean like for classes 2 - 6 i want it to be non clickable unless they have the certain amount of rank needed in the leaderboard

0

Keep in mind that the wait won't be consistent. You will need to use datastore to allow the user to pick a class weekly.

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