|
| 03 May 2016 02:41 PM |
Okay, So i have a leader board I've been using that utilizes money as the in-game currency. Specifically this is a racing game, so there are many cars to purchase in game and get a faster car than your friend. Anyways, I have a basic money leader board, but I want to add to it so every set amount of seconds, the player receives a little bit of cash. How would the script work that way so I can go about doing this? Thanks. |
|
|
| Report Abuse |
|
|
freez_man
|
  |
 |
| Joined: 24 Feb 2016 |
| Total Posts: 4514 |
|
| |
|
|
| 03 May 2016 02:44 PM |
(Next time please ask this in Scripters)
Leaderboards use a special value called "leaderstats", and inside of that all of your actual leaderboard values are inside. Each player is given this when they join the game. If you are using ROBLOX's default player list this is how it works. To reach it using a script, you would have to take this path:
game.Players.PLAYER_NAME_HERE.leaderstats.Money
I don't know if your stat is called "Money", but I'm assuming it is. To give them cash every second, put this code in a LocalScript inside of their PlayerGui (replace the values where I comment):
local player = game.Players.LocalPlayer local stats = player:WaitForChild("leaderstats") local money = stats:WaitForChild("Money") -- if it isn't called Money change it
local delayTime = 60 -- time, in seconds, between cash local cash = 10 -- amount of cash they get every [delayTime] seconds
while wait(delayTime) do money.Value = money.Value + cash end |
|
|
| Report Abuse |
|
|
|
| 03 May 2016 02:45 PM |
| Put this script inside of StarterGui*, sorry |
|
|
| Report Abuse |
|
|
|
| 03 May 2016 02:53 PM |
Sorry I didn't know there was a scripting section of the forum. I tried using it and roblox crashed 3:
this is my script that I'm using : print("Cash Leaderboard Loaded")
function onPlayerEntered(newPlayer)
local stats = Instance.new("IntValue") stats.Name = "leaderstats"
local cash = Instance.new("IntValue") cash.Name = "Money" --name of currency (e.g. cash, money, resources, bucks, etc.) cash.Value = 150 --starting money.
cash.Parent = stats stats.Parent = newPlayer end
game.Players.ChildAdded:connect(onPlayerEntered)
|
|
|
| Report Abuse |
|
|
|
| 03 May 2016 02:55 PM |
| it keeps crashing ROBLOX whenever i try to use it. |
|
|
| Report Abuse |
|
|
|
| 03 May 2016 02:56 PM |
| Alright then take it out, I messed up somewhere. That should've worked :/ |
|
|
| Report Abuse |
|
|
|
| 03 May 2016 02:59 PM |
when you posted this :
game.Players.PLAYER_NAME_HERE.leaderstats.Money
I didn't insert this into it because this isn't going to go to a specific person. So i got confused. Also, is this to be inserted into the original script? I made a separate script from the leaderboard. |
|
|
| Report Abuse |
|
|
|
| 03 May 2016 03:01 PM |
| That was just an example showing how you would get to one player. The original script I posted was a LocalScript that was supposed to be placed in your game's StarterGui (I messed up and said PlauerGui :P) |
|
|
| Report Abuse |
|
|
Dev_Ryan
|
  |
| Joined: 10 Mar 2013 |
| Total Posts: 243 |
|
|
| 03 May 2016 11:14 PM |
Like a previous player said, script help belongs in the scripter's forums, so if you need any further help, post it there and not here :P Link: https://forum.roblox.com/Forum/ShowForum.aspx?ForumID=33
Anyways, just to go ahead and answer your question.. here it is:
I wouldn't handle stats client side (localscript) as only the local player will see any changes and everyone else will constantly see other players having 0 in-game currency.
Do this in a normal server script inside: game.ServerScriptService
local cash = 10 -- amount of cash to give every second.
game.Players.PlayerAdded:connect(function(player) local pgui = player:WaitForChild("PlayerGui") local stats = Instance.new("Folder",pgui) stats.Name = "leaderstats" local money = Instance.new("NumberValue",stats) stats.Name = "Money" stats.Value = 0 end)
while true do wait(1) local players = game.Players:GetPlayers() for i = 1, #players do local ls = players[i]:FindFirstChild("leaderstats") if ls and ls:FindFirstChild("Money") then ls["Money"].Value = ls["Money"].Value + cash end end end
Hope this helps!
|
|
|
| Report Abuse |
|
|
Dev_Ryan
|
  |
| Joined: 10 Mar 2013 |
| Total Posts: 243 |
|
|
| 03 May 2016 11:16 PM |
Oops, I accidentally made an error. xD
Change where it says: local money = Instance.new("NumberValue",stats) stats.Name = "Money" stats.Value = 0
into: local money = Instance.new("NumberValue",stats) money.Name = "Money" money.Value = 0
|
|
|
| Report Abuse |
|
|