Tune in here this Saturday at 2pm Eastern Time to watch the staff play the Game Jam submissions and give their input with the community!
Vote now here!
Ad
Log in to vote
1

Why isnt this script that uses Spreadsheet(s) SAVING and LOADING my value?

Asked by
nanaluk01 236
2 months ago

Why isnt this script that uses GoogleSpreadsheet SAVING my value?

It posts the player's id and the value in the right place, but when the player leaves, it does not update the value in the spreadsheet. Why?

Also I have problems on line 14, where I need to get the value in the spreadsheet and insert it into the player's leaderstats.

databaseService = require(game.Workspace.DatabaseService) --//Gets the Database - module script
game.Players.PlayerAdded:connect(function(player)
    local id = player.UserId --//Gets the player's UserId


    local Brickcoins = player:WaitForChild("leaderstats"):WaitForChild("Brickcoins") --//The player's BrickCoins

    local globalDatabase = databaseService:GetDatabase("Global")
    if not globalDatabase:GetAsync("player-"..id) then --//if the player has not yet any data stored
        globalDatabase:PostAsync("player-"..id , Brickcoins.Value) --//Posts another "data" to the spreadsheet named for instance: "player-123456"
        print(globalDatabase:GetAsync("CoolPeople")) --//Prints the name of all the cool people stored in the database
        Brickcoins.Value = 0
    else --//And if the player has data stored, then
        Brickcoins.Value = globalDatabase:GetAsync() --//This is where I would need to get the player's saved value, but I have problems with figuring out how.
        --//Have to get the BrickCoins value the player has previously stored
    end
end)

game.Players.PlayerRemoved:connect(function(player)
    local id = player.UserId --//Gets the player's UserId

    local Brickcoins = player:WaitForChild("leaderstats"):WaitForChild("Brickcoins") --//The player's BrickCoins

    local globalDatabase = databaseService:GetDatabase("Global")
    globalDatabase:PostAsync("player-"..id , Brickcoins.Value) --Posts the player's name(currently) going to post the BrickCoins' value
    --//Have to update the BrickCoins - value the player has 
end)

Any help is greatly appreciated!

0
Are there any errors in the output after the player leaves? Have you tested to make sure the PostAsync call actually finishes? BlueTaslem 15407 — 2mo
0
Wouldn't providing GetAsync at line 14 with `"player-" .. id` achieve the desired effect? tkcmdr 296 — 2mo
0
There are no errors after the player leaves, @BlueTaslem. And how would I check the PostAsync call actually finishes? nanaluk01 236 — 2mo
0
you should probably store the info as a JSON, just my personal thought connor12260311 355 — 2mo
0
If you're posting to Google Spreadsheets, your API endpoint is probably misconfigured. Make sure your API keys and authentication are working. P100D 465 — 2mo

Hi.

Looks like you're using an ad blocker.

That's fine...

No, it really is.

Just, I mean, we put a lot of work into this site, you know?

It would be really really appreciated if you would turn off your ad blocker for our website...

We tried really hard to make our ads as unobtrusive as possible.

If you really hate ads, would you consider a $2 donation via Patreon?

Here's the link.

We love you. We hope you love us too.

.

..

...

Now back to your regularly scheduled Scripting Helpers....

...

..

.

Answer this question



Ad