0
votes

I'm new to Lua and Stack so I apologize in advance. I'm currently using a tycoon kit to create a Roblox game, and the player's money value only shows up on the leaderboard, but nowhere on the screen. This can make it hard to know how much money you have on console and mobile, so I'm trying to set up a GUI to display the player's amount of money on the screen. Now, setting up the GUI isn't the issue, knowing what to set the text value on the GUI is.

I do not know how to upload am image, but the path in my workspace looks a bit like this: Players (on the first tab of the workspace)-> Player-> leaderstats-> Cash

I've tried to grab the variable (named "Cash") like this: game.Players.Player.leaderstats.Cash.Value but because I'm not named "Player", it didn't work. I've tried replacing it with LocalPlayer (looked like game.Players.LocalPlayer.leaderstats.Cash.Value), but that also didn't work. It only works when I replace "Player" with my username (game.Players.Username.leaderstats.Cash.Value), but I want this to work for other players besides me.

I've also tried to locate the original variable, but because I did not make the kit I'm at a loss. I've looked in every script that comes with it, but could not find anything.

When I try to set the text to these values, nothing happens. The error message I get falls along the lines of Player is not a valid member of Players. Any help would be greatly appreciated!

2
I assume you could get the username of someone on the board, and assign that to a variable then use that variable in game.Players.Username as Username.Corsaka

2 Answers

1
votes

LocalPlayer Is a variable which is only on the client side to get the leaderstats of the LocalPlayer You need to use a local script instead of a normal script Now i will show you how you can display it first create your "ScreenGui" then create a "TextLabel" under the ScreenGui And finaly create a "LocalScript" Under the TextLabel Now the code should be in the LocalScript

game.Players.LocalPlayer.leaderstats.Cash.Changed:Connect(function(NewValue) --Chnage Cash to your stat
    script.Parent.Text = "$"..NewValue
end)
0
votes

at the start of the script put this:

local plr = game:GetService("Players").LocalPlayer

and at the part where it puts the money on the screen: (assuming the local script is in the textbox the money is in)

   while true do 
      script.Parent.Text = plr.leaderstats.Cash.Value
      wait()
   end

and that's all you have to do!

raw paste (just copy and paste this into a localscript inside a textbox)

local plr = game:GetService("Players").LocalPlayer

while true do 
   script.Parent.Text = plr.leaderstats.Cash.Value
   wait()
end