Greetings, I have a problem for so long that my data doesn’t save at all no matter what I tried. As you can see I moved on to Datastore2 since I have heard is much better, but it seems I don’t know why it doesn’t save. The code is down below.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local ServerScriptService = game:GetService("ServerScriptService")
local DataStore2 = require(ServerScriptService.DataStore2)
DataStore2.Combine("DATA", "coins", "Server", "Host", "Gamemode", "Difficulty", "Code")
Players.PlayerAdded:Connect(function(player)
local dataServer = DataStore2("Server", player)
local dataHost = DataStore2("Host", player)
local dataGamemode = DataStore2("Gamemode", player)
local dataDifficulty = DataStore2("Difficulty", player)
local dataCode = DataStore2("Code", player)
local folder = Instance.new("Folder", player)
folder.Name = "ServerCreator"
local Server = Instance.new("ObjectValue", folder)
local Host = Instance.new("ObjectValue", folder)
local Gamemode = Instance.new("NumberValue", folder)
local Difficulty = Instance.new("NumberValue", folder)
local Code = Instance.new("NumberValue", folder)
Server.Name = "Server"
Host.Name = "Host"
Gamemode.Name = "Gamemode"
Difficulty.Name = "Difficulty"
Code.Name = "Code"
--LOADING DATA--
if dataServer:Get() ~= nil then
Server.value = dataServer:Get()
print(Server.Value)
else
Server.Value = "None"
end
if dataHost:Get() ~= nil then
Host.value = dataHost:Get()
print(Host.Value)
else
Host.Value = "None"
end
if dataGamemode:Get() ~= nil then
Gamemode.value = dataGamemode:Get()
print(Gamemode.Value)
else
Gamemode.Value = 0
end
if dataDifficulty:Get() ~= nil then
Difficulty.value = dataDifficulty:Get()
print(Difficulty.Value)
else
Difficulty.Value = 0
end
if dataCode:Get() ~= nil then
Code.value = dataCode:Get()
print(Code.Value)
else
Code.Value = 0
end
--SAVING DATA--
Server.Changed:Connect(function()
dataServer:Set(Server.Value)
end)
Host.Changed:Connect(function()
dataHost:Set(Host.Value)
end)
Gamemode.Changed:Connect(function()
dataGamemode:Set(Gamemode.Value)
end)
Difficulty.Changed:Connect(function()
dataDifficulty:Set(Difficulty.Value)
end)
Code.Changed:Connect(function()
dataCode:Set(Code.Value)
end)
end)
No, I didn’t… I also tried in the actual game, not just in the studio and it didn’t work. But, how do I make it anyways? In my game, I have an Admin Panel that I use to show every data and player bans, etc. The data wouldn’t load in the game.
Make a SaveInStudio bool value in ServerStorage and set it to true/false if you want it to save in studio or not. DataStore2 will not save without this value existing.
I also have numbers not just objects. Then how can I save the host’s name and party name (since I am trying to do a party system). I transfer the data to a new place that has space for players to join in.
--LOADING DATA--
local serverData,hostData,GamemodeData,difficultyData,dataCodeData
local success,errorr = pcall(function()
serverData = dataServer:Get()
hostData = dataHost:Get()
GamemodeData = dataGamemode:Get()
difficultyData = dataDifficulty:Get()
dataCodeData = dataCode:Get()
end)
if success then
if serverData and hostData and GamemodeData and difficultyData and dataCodeData then
Server.Value = serverData
Host.Value = hostData
Gamemode.Value = GamemodeData
Difficulty.Value = difficultyData
Code.Value = dataCodeData
else
Server.Value = "None"
Host.Value = "None"
Gamemode.Value = 0
Difficulty.Value = 0
Code.Value = 0
end
elseif errorr then
error(errorr)
end
Hmm so its a problem with saving… let’s see
Saving part code, added pcall function to check errors.
--SAVING DATA--
local yes,no = pcall(function()
Server.Changed:Connect(function()
dataServer:Set(Server.Value)
end)
Host.Changed:Connect(function()
dataHost:Set(Host.Value)
end)
Gamemode.Changed:Connect(function()
dataGamemode:Set(Gamemode.Value)
end)
Difficulty.Changed:Connect(function()
dataDifficulty:Set(Difficulty.Value)
end)
Code.Changed:Connect(function()
dataCode:Set(Code.Value)
end)
end)
if yes then
print("Saved data for "..plr.Name)
elseif no then
error(no)
end
I am not good with DataStore2, and since you are not storing any Tables value.
Why not use roblox’s normal datastore with :SetAsync?
People says setAsync makes you lose data but only for tables not for single values.
I also use roblox’s datastore but since i have tables, I use :UpdateAsync and haven’t got any data lose reports.