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

How to save currency after buying currency in game ?

Asked by 5 years ago

So in my game I’ve made a currency shop and it’s working and everything but when you leave it doesn’t save and I’ve gone on YouTube and tried a bunch of data saving scripts but none are working this is my currency script please help me

game.Players.PlayerAdded:Connect(function(plr) local folder = Instance.new(“Folder”, plr) folder.Name = “leaderstats” local value = Instance.new(“IntValue”, folder) value.Name = “Money”

end)

Please help me :)

2 answers

Log in to vote
0
Answered by
Benbebop 1049 Moderation Voter
5 years ago

Assuming you incorrectly used DataStores, To insert/modify data in a DataStore array you must use SetAsync, UpdateAsync and RemoveAsync.

SetAsync creates a new value and modifies it to the parameters specified.

Ex.

1local DataStoreService = game:GetService("DataStoreService")
2local ExampleStore = DataStoreService:GetDataStore("ExampleData")
3 
4ExampleStore:SetAsync("ExamplePlayer", 50)

This creates a new value ExamplePlayer and sets it's corresponding value to 50.

UpdateAsync modifies an existing value to the parameters specified.

Ex.

1local DataStoreService = game:GetService("DataStoreService")
2local ExampleStore = DataStoreService:GetDataStore("ExampleData")
3 
4ExampleStore:UpdateAsync("ExamplePlayer", 50)

This changes ExamplePlayer's corresponding value to 50

RemoveAsync removes a value in the array.

Ex.

1local DataStoreService = game:GetService("DataStoreService")
2local ExampleStore = DataStoreService:GetDataStore("ExampleData")
3 
4ExampleStore:RemoveAsync("ExamplePlayer")

This removes ExamplePlayer and its corresponding value

For more see Data Stores.

Ad
Log in to vote
-1
Answered by 5 years ago

Here you go hope this helps also put this in server script service! Any questions? Just ask me!

01local datastore = game:GetService("DataStoreService") -- DONT CHANGE
02local ds1 = datastore:GetDataStore("GemSaveSystem") -- DONT CHANGE
03local ds2 = datastore:GetDataStore("CashSaveSystem") -- DONT CHANGE
04 
05game.Players.PlayerAdded:connect(function(plr)
06 local folder = Instance.new("Folder", plr)
07 folder.Name = "leaderstats"
08 local gems = Instance.new("IntValue", folder)
09 gems.Name = "HouseTickets" -- Change to your Currency
10 local cash = Instance.new("IntValue", folder)
11 cash.Name = "Cash" -- Change to your Currency
12 
13 gems.Value = ds1:GetAsync(plr.UserId) or 0
14 ds1:SetAsync(plr.UserId, gems.Value)
15 
View all 26 lines...
0
OMG IT WORKED THANK YOU SO MUCH Bssiemeow Gleamingdrawsocute -35 — 5y
0
OMG IT WORKED THANK YOU SO MUCH Bssiemeow Gleamingdrawsocute -35 — 5y
0
Thats all good :) Bssiemeow 30 — 5y

Answer this question