Ranks System Help

Hi, I’m trosscraft and I need help from something that the ranks system like those simulators have ranks.

Example: 100 coins = expert rank.

or example: 50 coins = Medium Rank.

Please, someone help me with this, I do not know very well this …

4 Likes

We can’t really help you without more information regarding your question, including what you’ve already tried to achieve this, and what specific area of your code you need help with. If you’d like somebody to develop a script for you, you’d probably be best posting in the public recruiment category.

If you’re brand new to scripting, you can check out these resources:

4 Likes

To do something like that you need to use a stringvalue.

Here is an example.

game.Players.PlayerAdded:Connect(function(plr)

    local folder = Instance.new("Folder",plr)

    folder.Name = "leaderstats"

    local coins = Instance.new("IntValue",folder)

    coins.Name = "coins"

    coins.Value = 0

    local rank = Instance.new("StringValue",folder)

    rank.Name = "rank"

    if coins.Value <= 49 then

        rank.Value = "Noob"

    end

    if coins.Value <= 99 and coins.Value >= 50 then

        rank.Value = "Better"

    end

    if coins.Value >= 100 then

        rank.Value = "Legend"

    end

    coins.Changed:Connect(function()

        if coins.Value <= 49 then

            rank.Value = "Noob"

        end

        if coins.Value <= 99 and coins.Value >= 50 then

           rank.Value = "Better"

        end

        if coins.Value >= 100 then

            rank.Value = "Legend"

        end

   end)

end)

5 Likes

You can use
```
– code
```
to format your code properly :slight_smile:

7 Likes

Thanks for the advice!

The only qualm I have with this piece of code is that it relies on you having to hard code nested if statements into your place, which isn’t scalable or edit-friendly once you start getting more ranks added.

I would recommend reading from a table consisting of ranks. I can give you a rudimentary solution but if anyone wants to come along and fix it, so be it.

local LevelTitles = {
	[100] = "Yes",
	[75] = "No",
	[50] = "Oh",
	[25] = "Person",
	[1] = "New"
}

for LevelRequirement, Title in pairs(LevelTitles) do
	if --[[(player level whatever here)]] >= LevelRequirement then
		--(set title)
	end
end

Something like this, I guess. One of the caveats of this though is relying on the order of entries in the table though, so I wouldn’t recommend using this raw. Good for beginners but unreliable in the long run.

2 Likes

TheFuzi’s example wasn’t good, bad practice. Instance.new() with 2 arguments is deprecated, should’ve used :GetService(). Also you can reduce the lines of code.
Your example is good however. What if you wanted to add new ranks? You would need to do rank checks in every script, instead you can use your method and just add a new rank to the dictionary and run a generic loop which changes the rank of the player.
I also suggest you wrap your generic loop in a function so you do not have to run that code every time you want to check for the player’s rank.

1 Like

The second argument of Instance.new isn’t actually deprecated.

2 Likes

I thought it was deprecated but either way it is better to avoid using Instance.new() with the second argument as a parent. I do not think I have to explain why, I do not have to repeat what zeuxcg said in this thread (aka the one you linked above).

2 Likes

People seem to be misunderstanding the reason you want to avoid using Instance.new’s second paramater which sets the parent of the object being created. In the case of these leaderstats, you should set the Parent of the leaderstats folder AFTER you’ve finished setting the entire thing up.

As far as performance goes, it’s better to initialize everything in one fell swoop for both performance (albeit minor here, since neither physics nor rendering cares about Folders and Value Objects) as well as logic reasons. Setting Name after Parent could cause a problem with WaitForChild, for example.

tl;dr: if you’re building a hierarchy of objects in code (like leaderstats) it’s usually fine to use the second parameter for children/descendants, just make sure your root object’s Parent is set LAST.

4 Likes