So Im creating a game, the scripts are perfectly fine. Their scripted by professionals, we turned on API services also. When I publish the game its not like it should be. Its not perfectly fine like in studio. What could be the issue?
Pro tip:
Before I get into answering your question, I would like to say that ROBLOX studio and the real game are to different things. What I mean is that some scripts works in studio and it doesn't work on the published game.
Why is that you may ask?
This is because the two environments are not the same, one may work in one side but doesn't work on the other. Besides that, the real test is the published game.
Solution:
The cause of your error may be that the datastore itself is not working, I think that the bug was that it didn't actually save with the Player:Removing
event
Since you didn't clearly, give a valid description that may not be the case.
You could try this script:
local DataStoreService = game:GetService("DataStoreService") local Event = game:GetService("ReplicatedStorage"):WaitForChild("Events"):WaitForChild("SaveMyStats") game.Players.PlayerAdded:Connect(function(player) local Stats = Instance.new("Configuration", player) Stats.Name = "Stats" -- Main stats local diamonds = Instance.new("IntValue", Stats) diamonds.Name = "Diamonds" diamonds.Value = DataStoreService:GetDataStore("DiamondDataStore"):GetAsync(player.UserId) or 0 local level = Instance.new("IntValue", Stats) level.Name = "Level" level.Value = DataStoreService:GetDataStore("LevelDataStore"):GetAsync(player.UserId) or 1 -- -- Other stats local parachute = Instance.new("StringValue", Stats) parachute.Name = "Parachute" parachute.Value = DataStoreService:GetDataStore("ParachuteDataStore"):GetAsync(player.UserId) or "Black" local skydiveseconds = Instance.new("IntValue", Stats) skydiveseconds.Name = "SkydiveSeconds" skydiveseconds.Value = DataStoreService:GetDataStore("SkydiveSecondsDataStore"):GetAsync(player.UserId) or 0 local tutorial = Instance.new("BoolValue", Stats) tutorial.Name = "Tutorial" tutorial.Value = DataStoreService:GetDataStore("TutorialDataStore"):GetAsync(player.UserId) or false -- end) function SaveMyStats(player) -- Main stats if player:FindFirstChild("Stats") then DataStoreService:GetDataStore("DiamondDataStore"):SetAsync(player.UserId, player.Stats:FindFirstChild("Diamonds").Value) local level = DataStoreService:GetDataStore("LevelDataStore"):GetAsync(player.UserId) if level ~= nil and level <= player.Stats:FindFirstChild("Level").Value then DataStoreService:GetDataStore("LevelDataStore"):SetAsync(player.UserId, player.Stats:FindFirstChild("Level").Value) elseif level == nil then DataStoreService:GetDataStore("LevelDataStore"):SetAsync(player.UserId, player.Stats:FindFirstChild("Level").Value) end -- -- Other stats DataStoreService:GetDataStore("ParachuteDataStore"):SetAsync(player.UserId, player.Stats:FindFirstChild("Parachute").Value) DataStoreService:GetDataStore("SkydiveSecondsDataStore"):SetAsync(player.UserId, player.Stats:FindFirstChild("SkydiveSeconds").Value) DataStoreService:GetDataStore("TutorialDataStore"):SetAsync(player.UserId, player.Stats:FindFirstChild("Tutorial").Value) end end game.Players.PlayerRemoving:Connect(SaveMyStats) Event.OnServerEvent:Connect(SaveMyStats)
If you want to change the stats just edit the leaderstats.
If you need to learn about datastore 's click here