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

Why doesn't my DataStore Work?

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

✓ Accepted answer

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.

1 comment

0

Thanks man!

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