Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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)

1 answer

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)

4 comments

0

Enjoy!

0

P.S Just leave this in workspace.

0

This will not work, I don't even see the DataStore service

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.