save and load data script doesen’t work with the error ServerScriptService.PlayerData.Data:58: attempt to index nil with Instance
-
What do you want to achieve? Keep it simple and clear!
i wanted to save and load player data however player joins/leaves the game -
What is the issue? Include screenshots / videos if possible!
my script isn’t working. it show the error ServerScriptService.PlayerData.Data:58: attempt to index nil with Instance -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
yes, i have tried searching about this particular topic with the same tutorial, but i come out empty-handed.
4.Additional information
my script was in serverscriptservice
i followed the following tutorial: The Best and Easiest Way To Save and Load Data
i used ProfileService
here is my 3 scripts:
the Data serverscript:
local players = game:GetService("Players")
local serverscriptservice = game:GetService("ServerScriptService")
local template = require(serverscriptservice.PlayerData.Template)
local manager = require(serverscriptservice.PlayerData.Manager)
local profileservice = require(serverscriptservice.OtherScripts.ProfileService)
local profilestore = profileservice.GetProfileStore("production", template)
local KICK_MESSAGE = "Sorry, we're having trouble gathering your data, please try again later"
local function createleaderstats(player: Player)
local profile = manager.profiles[player]
if not profile then return end
local folder1 = Instance.new("Folder", player)
folder1.Name = "leaderstats"
local folder2 = Instance.new("Folder", player)
folder2.Name = "stats"
local money1 = Instance.new("NumberValue", folder1)
money1.Name = "Coins"
money1.Value = profile.Data.Coins
local money2 = Instance.new("NumberValue", folder2)
money2.Name = "Meteorites"
money2.Value = profile.Data.Meteorites
end
local function loadprofile(player: Player)
local profile = profilestore:LoadProfileAsync("Player_"..player.UserId)
if not profile then
player:Kick(KICK_MESSAGE)
return
end
profile:AddUserId(player.UserId)
profile:Reconcile()
profile:listentorelease(function()
manager.profiles[player] = nil
player:kick(KICK_MESSAGE)
end)
if player:IsDescendantOf(players) == true then
manager.profiles[player] = profile
createleaderstats(player)
else
profile.Release()
end
end
for _, player in players:GetPlayers() do
task.spawn(loadprofile, player)
end
players.PlayerAdded:Connect(loadprofile)
players.PlayerRemoving:Connect(function(player)
local profile = manager.Profiles[player]
if profile then
profile:Release()
end
end)
the manager modulescript:
local manager = {}
manager.profiles = {}
return manager
the template modulescript:
local template = {
Coins = 200,
Meteorites = 0
}
return template
all of that is probably all of the information that i can give, all helps will be appriciated!
thanks!
if i didn’t respond within a hour, i was at school or i was sleeping.