So I don’t understand why it doesn’t work. The values add up, no errors pop up, but the script doesn’t print anything in the console + and it doesn’t save my data. I am struggling with this for some time and I couldn’t find a solution anywhere. My script is below:
local Players = game:GetService("Players")
local DSS = game:GetService("DataStoreService")
local ServerCreator = DSS:GetDataStore("ServerCreator")
local function AddPlr(Plr)
local servercreator = Instance.new("Folder")
servercreator.Name = "ServerCreator"
servercreator.Parent = Plr
local servername = Instance.new("ObjectValue")
servername.Name = "ServerName"
servername.Parent = servercreator
local gamemode = Instance.new("NumberValue")
gamemode.Name = "Gamemode"
gamemode.Parent = servercreator
local difficulty = Instance.new("NumberValue")
difficulty.Name = "Difficulty"
difficulty.Parent = servercreator
local code = Instance.new("NumberValue")
code.Name = "Code"
code.Parent = servercreator
local host = Instance.new("ObjectValue")
host.Name = "Host"
host.Parent = servercreator
local PotentialData
local success, whoops = pcall(function()
PotentialData = ServerCreator:GetAsync(Plr.UserId)
end)
if success and PotentialData then
servername.Value = PotentialData.servername
gamemode.Value = PotentialData.gamemode
difficulty.Value = PotentialData.difficulty
code.Value = PotentialData.code
host.Value = PotentialData.host
print("Data successfully loaded for Player:", Plr)
else
warn("Error attempting to load the data:", whoops)
end
end
local function RemovePlr(Plr)
local servername = Plr:WaitForChild("ServerCreator"):WaitForChild("ServerName")
local gamemode = Plr:WaitForChild("ServerCreator"):WaitForChild("Gamemode")
local difficulty = Plr:WaitForChild("ServerCreator"):WaitForChild("Difficulty")
local code = Plr:WaitForChild("ServerCreator"):WaitForChild("Code")
local host = Plr:WaitForChild("ServerCreator"):WaitForChild("Host")
local DataToSave = {
ServerName = servername.Value,
Gamemode = gamemode.Value,
Difficulty = difficulty.Value,
Code = code.Value,
Host = host.Value
}
local success, whoops = pcall(function()
ServerCreator:SetAsync(Plr.UserId, DataToSave)
end)
if success then
print("Data successfully saved for Player", Plr)
else
warn("Error attempting to save the data:", whoops)
end
end
Players.PlayerAdded:Connect(AddPlr)
Players.PlayerRemoving:Connect(RemovePlr)
Need fast help, please! Thanks.