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

I can't save money data and I don't know why?

Asked by
sheepposu 561 Moderation Voter
6 years ago
Edited 6 years ago

I've stayed up all night trying to get this to work but it just wouldn't . The code makes sense to me, so I can't figure out why it won't work. The output says no errors, just returning a nil value for trying to find the player Id. Which means it is not properly saving my Id to the data bank.

Heres the code. I've labeled it. The code is in a regular script inside 'ServerScriptService'

01--Creates the data Store as ds
02local ds = game:GetService("DataStoreService"):GetDataStore("-xBuckDatax-")
03 
04game.Players.PlayerAdded:Connect(function(player)
05    -- saves the player Id as key
06    local key = "Player_"..player.UserId
07    local folder = Instance.new("Folder",player)
08    folder.Name = "leaderstats"
09    local money = Instance.new("IntValue",folder)
10    money.Name = 'ObbyBucks<|>'
11    local moneyalready
12    --moneyalready is the id of the player
13    local success, err = pcall(function()
14        moneyalready.Value = ds:GetAsync(key)
15    end)
View all 31 lines...
0
I noticed on line 14 that you have the Value you want to save indexed in the get async parameters you just need to Put the key Inside and leave out the "BlahBlah.Value" so: DataStore:GetAsync(Key) Cyrakohl 108 — 6y

1 answer

Log in to vote
1
Answered by
zblox164 531 Moderation Voter
6 years ago
Edited 6 years ago

You should save using tables. This will make it easier in the future to add other values too. I fixed up your code below but keep in mind this is untested.

01local Players = game:GetService("Players")
02local DataStoreService = game:GetService("DataStoreService")
03local DataStore = DataStoreService:GetDataStore("-xBuckDatax-")
04 
05-- Making the saving inside a function it shortened your code by a bit.
06local function Save(player)
07    local key = "Player_"..player.UserId
08 
09    local save = {
10        ["ObbyBucks"] = player.leaderstats["ObbyBucks<|>"].Value
11    }
12 
13    --saves their key and money to the data store
14    local success, err = pcall(function()
15        DataStore:SetAsync(key, save)
View all 56 lines...

All I did was improve the code.

What I did:

Split the DataStore variables, made the saving and loading in a function that you control when it's called, editing the save and load system, removed deprecated code.

More information on DataStores

0
So the past 40 min I have been testing it and looking over it and finally I've come out with it not working. This script is great. Thankyou. I posted a vid of me testing it out right here - https://youtu.be/VB7j4XKfXgM You may be able to find the prob. sheepposu 561 — 6y
0
Im going to assume he solved your problem from that comment alone so I'll accept the answer on your behalf. Next time accept the answer that helped you the most. User#24403 69 — 6y
0
It didn't solve my problem tho sheepposu 561 — 6y
0
Do you have data stores enabled? zblox164 531 — 6y
Ad

Answer this question