Hey developers! So this might be a very nonsensical question but I read through my code and I couldn’t spot anything wrong. If you can please let me know. I was making a DataStore for a game that I’m working on and I made it so that if the Data Saves, it prints a string, and if it fails it prints another string. (I followed this from the Wiki I believe). Feedback would be much appreciated, thanks and cheers!
To clarify: I should be seeing the strings printed in the output window but it’s completely blank.
Here’s the code written in the ServerScriptService on a Server Script.
local DataStoreService = game:GetService("DataStoreService") local DataStore = DataStoreService:GetDataStore("UniD") game.Players.PlayerAdded:Connect(function(player) local leaderstats = Instance.new("Folder") leaderstats.Name = "leaderstats" leaderstats.Parent = player local coins = Instance.new("IntValue") coins.Name = "Coins" coins.Parent = leaderstats coins.Value = 0 local gems = Instance.new("IntValue") gems.Name = "Gems" gems.Parent = leaderstats gems.Value = 0 local rebirths = Instance.new("IntValue") rebirths.Name = "Rebirths" rebirths.Parent = leaderstats rebirths.Value = 0 local PlayerID = "PlayerID_"..player.userId local DataFetching local SuccessfulFetch, UnsuccessfulFetch = pcall(function() local DataFetching = DataStore:GetAsync(player.UserId) end) if SuccessfulFetch then coins.Value = DataFetching gems.Value = DataFetching rebirths.Value = DataFetching end end) game.Players.PlayerRemoving:Connect(function(player) local PlayerID = "PlayerID_"..player.UserId local CoinData = player.leaderstats.Coins.Value local GemData = player.leaderstats.Gems.Value local RebirthData = player.leaderstats.Rebirths.Value local SuccessfulFetch, UnsuccessfulFetch = pcall(function() DataStore:SetAsync(PlayerID, CoinData, GemData, RebirthData) end) if SuccessfulFetch then print("I gots the Data! :D") else print("Oh noes, I failed to gets the data! D:") warn(UnsuccessfulFetch) end end)