Hello
I wanted to make a DataStore script for my game (Script in ServerScriptService) and I tried using that and it doesn't work, can someone explain me why? The script including 49 lines.
Here is the script:
ocal DataStoreService = game:GetService("DataStoreService") local myDataStore = DataStoreService:GetDataStore("myDataStore") 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 local playerUserId = "Player_"..player.UserId local data local success, errormessage = pcall(function() data = myDataStore:GetAsync(playerUserId) end) if success then Coins.Value = data end end) game.Players.PlayerRemoving:Connect(function(player) local playerUserId = "Player_"..player.UserId local data = player.leaderstats.Coins.Value local success, errormessage = pcall(function() myDataStore:SetAsync(playerUserId, data) end) if success then print("Data successfully saved!") else print("There was an error!") warn(errormessage) end end)
This often happens because API services are not enabled in roblox studio. Click "Game Settings" in the top bar and select "Permissions". There you will see an option to enable roblox API services. Enable the option and test the game again. It will be working fine.