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

Why doesn't my DataStore Work?

Asked by 8 years ago

In the first script I made the table and DataStore

DataStore = game:GetService("DataStoreService"):GetDataStore("User")

game.Players.PlayerAdded:connect(function(Player)
    local Leaderboard = Instance.new("IntValue", Player)
    Leaderboard.Name = "leaderstats"

    local Stage = Instance.new("IntValue", Leaderboard)
    Stage.Name = "Stage's" 

    local Death = Instance.new("IntValue", Leaderboard)
    Death.Name = "Death's"

    local key = "Player:"..Player.userId
    local SaveData = DataStore:GetAsync(key) 

    if SaveData then
        Stage.Value = SaveData[1]
        Death.Value = SaveData[2]
    else
local Save = (Stage.Value , Death.Value)
    DataStore:SetAsync(key, Save)

end
end)

But it Had a Error message saying:

Workspace.LinkedLeaderboard:20: ')' expected near ','

I also Have another script that save the player's stats every time they leave but that doesn't seem to work

DataStore = game:GetService("DataStoreService"):GetDataStore("User")

game.Players.PlayerRemoving:connect(function(Player)
    local Save = (game.Player.leaderstats["Stage's"].Value , game.Player.leaderstats["Death's"].Value)
    local key = "Player:"..Player.userId    

    DataStore:SetAsync(key, Save)
end)

The error message on this is script is:

Workspace.LinkedLeaderboard.Script:4: ')' expected near ','

If you want anymore information about the script please comment below! :)

1 answer

Log in to vote
1
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
8 years ago

Tables in Lua are made using curly braces: {}, not parentheses: ().

Line 20 in your first script:

local Save = (Stage.Value , Death.Value) --This errors because you're not calling any function.
--local Save = (Stage.Value) would be valid code, which is why you got the specific error you did.

--I assume you meant to create a Table here, as per your Question:
local Save = {Stage.Value, Death.Value}

And Line 4 in the second:

local Save = (game.Player.leaderstats["Stage's"].Value , game.Player.leaderstats["Death's"].Value)
--Same problem, but one more as well! `game.Player` is invalid, but since that is in a PlayerRemoving function, it's an easy fix:
local Save = {Player.leaderstats["Stage's"].Value, Player.leaderstats["Death's"].Value}

Lastly, and this is just a typo, "Death's" and "Stage's" should be "Deaths" and "Stages". They're using plural, not possessive, ss.

0
Thanks man! UserOnly20Characters 890 — 8y
Ad

Answer this question