GUI that says leaderstat value

TUTORIAL #2 - Intermediate

How to make a GUI that tells you your Cash\Coin value

As you know, mobile players can not see the leaderstats. So, it’s nice to have a GUI that tells them their Coin\Cash value. This is also for ALL device users.

STEP 1: Create the leaderstats

Insert a Script into the Workspace.

To do this, click the “+” button.

Capture4849884

Now, insert the Script. Name it ‘leaderstats’.

Capturebboib

Insert the following code:

`

> game.Players.PlayerAdded:Connect(function(player)

`

local leaderstats = Instance.new("Folder",player)
leaderstats.Name = "leaderstats"


local coins = Instance.new("IntValue", leaderstats)
coins.Name = "Coins" -- Change  name to your liking.
coins.Value = 100

end

As you can see, it does this.

binihno

STEP 2: MAKE YOUR GUI

For the sake of this tutorial, I will not show you how to make a GUI because this is not a tutorial for that.

If you would like to know how to make a GUI look at this post:

How to Make a GUI

Here’s mine:

b wfibufiw

STEP 3: Coding the GUI

Now, for the final step; making the GUI that says your Coin\Cash value.

Inside your GUI insert a local script into the TextLabel.

b wfibufiwyh8y80

Insert the following code:

local player = game.Players.LocalPlayer

local leaderstats = player:WaitForChild("leaderstats")

local coins = leaderstats:WaitForChild("Coins") --Change according to the Name 

local text = script.Parent

text.Text = coins.Value

coins:GetPropertyChangedSignal("Value"):Connect(function()

text.Text = coins.Value

end)

STEP 4: TEST IT

If all success then;
Capturebiivbrwiobfoiew
Not only this should tell you your amount but also…
dfiowbfioewrw

I hope this tutorial helped you. If you have any question, leave them down below.

Getting topic locked due to many reasons.

6 Likes

Thank You for teaching me this info I will use this in the furture soon.

2 Likes

Do you know how to make one that shows Kills/Deaths?

2 Likes

I’m gonna do that in a different tutorial.

3 Likes

I would also recommend using GetService as it’s the most canical way for retrieving services, that is however explicitly preference based for Players

1 Like

Don’t know what your saying. As well as, getting the service is not gonna make a difference, really. :man_facepalming:

1 Like

Please throughly read the topic linked, using the Parent argument causes major performance flaws. GetService is preferred as it creates services that aren’t already created and is useful for getting services with odd names (such as “Run Service”), it isn’t exactly required for Players however.

Read more here:

1 Like

Okay, I’m good. You could’ve DMed me instead of trying to correct me out in the open on a reply. Regardless, this works. Not everything has to be your way of doing things.

He’s trying to help you out with this tutorial as his replies stated, using :GetService() instead of using game.Players.LocalPlayer as it’s more efficient and beneficial for you as a scripter and many others using this tutorial.

It helps that specific line to return with that service instead of calling out game.Players.LocalPlayer which isn’t very efficient for the script and user.

5 Likes

@loueque is correct.

This is a forum, where feedback and mild criticism is accepted. Not everyone’s perfect, so without feedback, you won’t get better. @ReturnedTrue did say everything very respectfully, so I do not see any problem with it.

It isn’t about “your way” or “my way” in scripting, it’s about the most efficient way.

Also, since it’s a correction, it’s best if everyone else can see and learn that that correction is the more efficient way. For example, he did reccomend not to use the parent parameter in Instance.new(object, parent) because a faster way is to simply do:

part = Instance.new("Part") -- create first
part.Anchored = true -- the properties in between
part.Parent = workspace --paren it LAST 

One last thing:
When you use “-Value” objects such as an IntValue, NumberValue, StringValue, etc, you don’t have to use :GetPropertyChangedSignal("Value"). You probably agree that it is very long to write, which all beats down to the question of efficiency. Instead, you can just use .Changed:

valueObj.Changed:Connect(function() --this function only runs when the Value changed, no other property

    print(valueObj.Value)

end)

Here’s what the DevHub says:


https://developer.roblox.com/en-us/api-reference/event/Instance/Changed

So, it’s an exception for “-Value” objects only.

4 Likes

I tried using .Changed. It doesn’t work that way sadly. I also don’t agree with neither of them. (Also, disagreement is okay. And not everyone will agree.)

I know it’s feedback but that doesn’t mean I have to take it.

I also tried doing it without Instance.new. That also did not work for me either.

I would also appreciate it if you would lock the topic please. (If you can.)

1 Like

Cool! I was thinking of making a scripting tutorial on yt (because thats what I do) but you beat me to it!

Nice script tutorial though!

1 Like

Yeah but that would still make the leaderstats appear in the normal player list.

Yeah, it’s suppose to appear on the Player List and the GUI. That’s the whole point-

So this tutorial would literally be make a leaderstats with just some extra steps?

What? Did you not read the whole thing and the title. If so, read over both…again.

I would recommend writing a tutorial on a more significant development topic that has utility to many developers. Creating leaderstats is already covered by the Developer Hub and resources exist for making these as well.

Please remember to review our category guidelines for more information on how to write tutorials:


Please also ensure that you are fully knowledgeable on the material you want to teach if you intend to be writing a Community Tutorial. This tutorial teaches several bad code practices that novice developers should not be falling into the habit of.

Immediately, your tutorial places a script in the Workspace. This is an antiquated method of storing code and should not be done. All scripts should be placed in ServerScriptService. If you have any reason to place a script in the Workspace, then it should be a configuration ModuleScript for a specific entity or because it logically makes sense to be there.

GetService is lacking in your uses of services. You should strive to remain consistent and stick to canonical conventions: as well, GetService ensures that you can find services by their class name and not their direct name. Some services like UserInputService aren’t named properly so you’ll have some cases of GetService and some without: this botches readability.

If you are modifying properties of an instance besides the parent, avoid using the second argument. Someone already linked the thread here. In addition to that thread, try parenting children first and then the actual root ancestor last.

local leaderstats = Instance.new("Folder")

local coins = Instance.new("IntValue")
coins.Name = "Coins"
coins.Value = 100

coins.Parent = leaderstats
leaderstats.Parent = player

Code working with PlayerAdded should also account for players that may already be in the server before the script starts executing. In this case, you can save the function into a variable, then have it listen to PlayerAdded as well as run on any existing players.

local Players = game:GetService("Players")

local function playerAdded(player)
    -- Code
end

Players.PlayerAdded:Connect(playerAdded)
for _, player in ipairs(Players:GetPlayers()) do
    playerAdded(player)
end

Step 2 is left incomplete. Tutorials should have a comprehensive detailing of the material you are covering, and not be left half baked. Please consider finishing that or revisiting writing a tutorial when you are more appropriately able to fill out that information.

That’s not how the forum works. Threads aren’t locked unless there is a moderation need to do so. If the request is solely due to the criticism its currently receiving, that’s not a valid reason to lock this thread. It may, on the other hand, be locked given that this is not a significant resource nor appropriate use of the tutorials category.

Please familiarise yourself with our rules before creating threads. :slight_smile:

7 Likes

Well, I’m gonna flag my own post. Also, anyone reading this, start being rude to me so this post can be locked.

Step 2 is left incomplete. Tutorials should have a comprehensive detailing of the material you are covering, and not be left half baked. Please consider finishing that or revisiting writing a tutorial when you are more appropriately able to fill out that information.

I don’t get it. I’m not baking anything? I didn’t make a bakery game.

Also, DM me instead next time. This is gonna create clutter.

You say use DMs, but yet your not doing it yourself.

Let’s not encourage misuse of the forums. I’m afraid that’s not a discussion appropriate to be having here as I was giving you some pointers, respectfully, about the thread as well as your use of the category. :slight_smile:

The term “half baked” is an expression which correlates to the tutorial not fully covering the material you’re trying to discuss in detail. Step 2 makes a lot of assumptions about the reader’s capabilities in development as opposed to being thorough, which is what this category is all about. If you wish to write about something, you should go all the way through.

I would be happy to discuss feedback with you further in DMs, as well as content that is not appropriate to be in a public reply. Constructive criticism, feedback or otherwise tips regarding the thread themselves should be posted here however as the Developer Forum is a public resource, and other developers should have access to this information to avoid falling into bad habits.

6 Likes