Heyo, so I have been struggling to get my first DataStore up and running using the script provided on the wiki so I decided to fire up this plugin by Crazyman so I can see what is, or isnt, in my DataStore tables. This post is specifically about the plugin, I will keep any DataStore related question for another thread/time.
SO then, the plugin does not seem to connect to my DataStore. From watching to tutorial, we can see that once you input the place idea, either manually or by default, it should give some feedback on the place, and creator. Mine does not do this, see image:
I am using the default code provided from the wiki and the name given the DataStore in that code is âPlayerDataâ I do believe, pasting that code again for reference, below.
Thanks for your help!
-- Set up table to return to any script that requires this module script
local PlayerStatManager = {}
local DataStoreService = game:GetService("DataStoreService")
local playerData = DataStoreService:GetDataStore("PlayerData")
-- Table to hold player information for the current session
local sessionData = {}
-- Function that other scripts can call to change a player's stats
function PlayerStatManager:ChangeStat(player, statName, value)
local playerUserId = "Player_" .. player.UserId
if tonumber(sessionData[playerUserId][statName]) and tonumber(value) then
sessionData[playerUserId][statName] = sessionData[playerUserId][statName] + value
else
sessionData[playerUserId][statName] = value
end
end
-- Function to add player to the 'sessionData' table
local function setupPlayerData(player)
local playerUserId = "Player_" .. player.UserId
local success, data = pcall(function()
return playerData:GetAsync(playerUserId)
end)
if success then
if data then
-- Data exists for this player
sessionData[playerUserId] = data
else
-- Data store is working, but no current data for this player
sessionData[playerUserId] = {Money=10, Experience=10}
end
else
error("Cannot access data store for player!")
end
print (playerUserId)
print (sessionData.Money)
end
-- Function to save player's data
local function savePlayerData(playerUserId)
if sessionData[playerUserId] then
local success, err = pcall(function()
playerData:SetAsync(playerUserId, sessionData[playerUserId])
end)
if not success then
error("Cannot save data for player!")
end
end
end
-- Function to periodically save player data
local function autoSave()
while wait(60) do
for playerUserId, data in pairs(sessionData) do
savePlayerData(playerUserId)
end
end
end
-- Start running 'autoSave()' function in the background
spawn(autoSave)
-- Connect 'savePlayerData()' function to 'PlayerRemoving' event
game.Players.PlayerRemoving:Connect(function(player)
local playerUserId = "Player_" .. player.UserId
savePlayerData(playerUserId)
end)
-- Connect 'setupPlayerData()' function to 'PlayerAdded' event
game.Players.PlayerAdded:Connect(setupPlayerData)
return PlayerStatManager