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

my save currency script isn't working anymore?

hi, i made a save currency script but and it worked, but after a few hours it didn't work anymore. i feel it may be because i got some of the currency on studio but if you know a definite reason to why this may have happened please tell me.

here is the script if it helps:

local DataStore = game:GetService("DataStoreService")
local ds = DataStore:GetDataStore("CashSaveSystem")

game.Players.PlayerAdded:connect(function(player)
	local leader = Instance.new("Folder",player)
	leader.Name = "leaderstats"
	local PowerBlocks = Instance.new("IntValue",leader)
	PowerBlocks.Name = "PowerBlocks"
	PowerBlocks.Value = ds:GetAsync(player.UserId) or 0
	ds:SetAsync(player.UserId, PowerBlocks.Value)
	PowerBlocks.Changed:connect(function()
		ds:SetAsync(player.UserId, PowerBlocks.Value)
	end)
end)


game.Players.PlayerRemoving:connect(function(player)
	ds:SetAsync(player.UserId, player.leaderstats.PowerBlocks.Value)
end)

thanks in advance from poopypigeon245

1 comment

0

update: ive noticed that it'll load your currency if you rejoin about two times so take this into consideration while writing an answer

2 answers

There are a few things to take into consideration:

Datastores will only work in studio if you Enable Studio Access to API services. Datastores have limits, you cannot save infinitly, so I recommend saving on a regular basis, such as every 5-20 minutes.

After considering these, make sure it still doesn't work. If it doesn't work, you should probably post your GetAsync code and make sure that's correct. Your code looks fine except the fact that it might overflow the limits. Here's some helpful links:

ROBLOX Wiki: Datastores

ROBLOX Wiki: Datastore Limitations

Try wrapping the DataStore GetAsync function in a pcall.

PowerBlocks.Value = pcall (function ()
return ds:GetAsync(player.UserId) or 0 end)

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