The Problem:
I had a group of developers commissioned for developing a game I’m working on releasing shortly. I was running through making sure everything is functionable for release. After conducting some tests, I noticed that the coins value is not saving. I am not sure about EXP, as EXP has not been set up yet. But I would assume that if the coins value is not saving, neither would the EXP value.
I personally can’t find anything wrong in the script that would be preventing the coins value from being saved, and no errors occurred in the dev console. Any help towards the right direction here would be greatly appreciated.
--// Services
local Players = game:GetService("Players")
local DatastoreService = game:GetService("DataStoreService")
--//Vars
local CoinsDatastore = DatastoreService:GetDataStore("Coins")
local ExpDatastore = DatastoreService:GetDataStore("Exp")
--//Datastore Function
local function RetrievePlayerData(Player : Player)
local UserId = Player.UserId
return CoinsDatastore:GetAsync(UserId), ExpDatastore:GetAsync(UserId)
end
--//Startup
local function PlayerSetup(Player : Player)
local HiddenFolder = Instance.new("Folder")
local CoinsValue = Instance.new("IntValue")
local EXPValue = Instance.new("IntValue")
HiddenFolder.Name = "Stats"
CoinsValue.Name = "Coins"
EXPValue.Name = "Experience"
local succ, Coins, Exp = pcall(RetrievePlayerData(Player))
if Coins and Exp then
CoinsValue.Value = Coins
EXPValue.Value = Exp
end
CoinsValue.Parent = HiddenFolder
EXPValue.Parent = HiddenFolder
HiddenFolder.Parent = Player
CoinsValue.Changed:Connect(function()
local succ, err = pcall(function()
CoinsDatastore:SetAsync(Player.UserId, CoinsValue.Value)
end)
end)
EXPValue.Changed:Connect(function()
local succ, err = pcall(function()
ExpDatastore:SetAsync(Player.UserId, EXPValue.Value)
end)
end)
end
Players.PlayerAdded:Connect(PlayerSetup)