Hey guys I have followed this wiki http://wiki.roblox.com/index.php?title=Saving_Player_Data and have made a script with tables like so
-- Setup table that we will return to scripts that require the ModuleScript.
local PlayerStatManager = {}
local DataStoreService = game:GetService('DataStoreService')
local playerData = DataStoreService:GetDataStore('PlayerData')
-- Table to hold all of the player information for the current session.
local sessionData = {}
-- Function the other scripts in our game can call to change a player's stats. This
-- function is stored in the returned table so external scripts can use it.
function PlayerStatManager:ChangeStat(player, statName, changeValue)
sessionData[player][statName] = sessionData[player][statName] + changeValue
end
-- Function to add player to the sessionData table.
local function setupPlayerData(player)
local data = playerData:GetAsync(player.UserId)
if not data then
data = {hp = 0, xp = 0}
playerData:SetAsync(player.UserId, sessionData[player])
end
sessionData[player] = data
end
-- Bind setupPlayerData to PlayerAdded to call it when player joins.
game.Players.PlayerAdded:connect(setupPlayerData)
local function savePlayerData(player)
playerData:SetAsync(player.UserId, sessionData[player])
end
game.Players.PlayerRemoving:connect(function(player)
savePlayerData(player)
-- We don't need to keep track of the data anymore
sessionData[player] = nil
local DataStore = game:GetService("DataStoreService")
local ds1 = DataStore:GetDataStore("coincurrency")
print("Saving currency to data store...")
ds1:SetAsync(player.UserId, player.leaderstats.Coins.Value)
print("Currency Saved")
end)
-- Return the PlayerStatManager table to external scripts can access it.
return PlayerStatManager
I want to have another script that will check if the values hp and xp are a certain number and then do something if they are, so I tried making this script
local DataStoreService = game:GetService('DataStoreService')
local playerData = DataStoreService:GetDataStore('PlayerData')
local function setupPlayerData(player)
local data = playerData:GetAsync(player.UserId)
if data = {hp = 0, s = 0} then
print("Blah")
end
end
Though as you can see....this does not seem to be correct, I hope this is not a request but can someone steer me into the right direction as to what I need to do? I am confused as to how this works in general.

1 comment
Edited to fix code formatting