Hi, I made it so every 60 seconds or 1 minute, you get 50 cash, but It doesn't save, how do I use datastorage? pls help, thanks.
01 | function onPlayerEntered(newPlayer) |
02 |
03 | local stats = Instance.new( "IntValue" ) |
04 | stats.Name = "leaderstats" |
05 |
06 | local cash = Instance.new( "IntValue" ) |
07 | cash.Name = "Cash" |
08 | cash.Value = 100 |
09 |
10 | cash.Parent = stats |
11 | stats.Parent = newPlayer |
12 | while true do |
13 | cash.Value = cash.Value + 50 |
14 | wait( 60 ) |
15 | end |
16 | end |
17 |
18 |
19 |
20 | game.Players.ChildAdded:connect(onPlayerEntered) |
This is a pretty simple script I made for my game. In my game, I made it so it saves the minutes (currency) of the player on the leaderboard. Here's the script
01 | function onPlayerEntered(player) |
02 | wait() -- Change to wait for player longer. |
03 | player:WaitForDataReady() |
04 | repeat wait() until player:FindFirstChild( "leaderstats" ) |
05 | if player.DataReady then |
06 | if player:findFirstChild( "leaderstats" ) then |
07 | local score = player.leaderstats:GetChildren() |
08 | for i = 1 ,#score do |
09 | local ScoreLoaded = player:LoadNumber(score [ i ] .Name) |
10 | wait() |
11 | if ScoreLoaded ~ = 0 then |
12 | score [ i ] .Value = ScoreLoaded |
13 | end |
14 | end |
15 | end |
Marked as Duplicate by Shawnyg
This question has been asked before, and already has an answer. If those answers do not fully address your question, then please ask a new question here.
Why was this question closed?