Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I make it so the cash saves? Please help! [closed]

Asked by
piRadians 297 Moderation Voter
7 years ago

This question already has an answer here:

How to use DataStores?

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.



function onPlayerEntered(newPlayer) local stats = Instance.new("IntValue") stats.Name = "leaderstats" local cash = Instance.new("IntValue") cash.Name = "Cash" cash.Value = 100 cash.Parent = stats stats.Parent = newPlayer while true do cash.Value = cash.Value + 50 wait(60) end end game.Players.ChildAdded:connect(onPlayerEntered)

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?

1 answer

Log in to vote
-1
Answered by 7 years ago
Edited 7 years ago

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

function onPlayerEntered(player)
wait()-- Change to wait for player longer.
player:WaitForDataReady()
repeat wait() until player:FindFirstChild("leaderstats")
if player.DataReady then
if player:findFirstChild("leaderstats") then
local score = player.leaderstats:GetChildren()
for i = 1,#score do
local ScoreLoaded = player:LoadNumber(score[i].Name)
wait()
if ScoreLoaded ~= 0 then
score[i].Value = ScoreLoaded
end
end
end
end
end

function onPlayerLeaving(player)
if player:findFirstChild("leaderstats") then
local score = player.leaderstats:GetChildren()
for i = 1,#score do
player:SaveNumber(score[i].Name,score[i].Value)
end
end
end

game.Players.PlayerAdded:connect(onPlayerEntered)
game.Players.PlayerRemoving:connect(onPlayerLeaving)

0
Enjoy! ReallyAdvanced -2 — 7y
0
P.S Just leave this in workspace. ReallyAdvanced -2 — 7y
0
This will not work, I don't even see the DataStore service greatneil80 2647 — 7y
0
You're using deprecated terms in this script. 'SaveNumber' is associated with Data Persistence, which has long been deprecated. DataStore is the new way to save data. Shawnyg 4330 — 7y
Ad