Having Trouble with data store

I have a obby game I am working on, and i am trying to load Player leaderstats using GetAsync… it will not load

Heres my script:

local obbyStages = workspace:WaitForChild(“Stages”)
Players = game:GetService(“Players”)

CurrentCheckPoint = {}
local CheckPointSpawn = game.Workspace.Stages:GetChildren()

local DataStoreService = game:GetService(“DataStoreService”)

local GameDATA = DataStoreService:GetDataStore(“PlayerExperience”)

function newPlayer(plr)
local stats = Instance.new(“Folder”)
stats.Name = “leaderstats”
stats.Parent = plr

local Stage = Instance.new(“IntValue”)
Stage.Name = “Stage”
Stage.Parent = stats
Stage.Value = 1

local data
local success, currentExperience = pcall(function()

  data = GameDATA:GetAsync(plr.UserId,  plr.leaderstats.Stage.Value)

end)

if success then
print(data)

else
print(“Data couldnt load”)

end

local TempChar = plr.Character

if TempChar ~= nil then
NewCharacter(plr, TempChar)
end
plr.CharacterAdded:connect(function(Char)
NewCharacter(plr, Char)
end)

end

function NewCharacter(plr, Char)
local TempCurrentCheckPoint = plr.leaderstats.Stage.Value
if TempCurrentCheckPoint ~= nil then
local TempCheckPointSpawn = workspace.Stages:WaitForChild(TempCurrentCheckPoint)
repeat wait () until Char.PrimaryPart ~= nil
Char.PrimaryPart.CFrame = TempCheckPointSpawn.CFrame + Vector3.new(0,1,0)
end
end

Players.PlayerAdded:connect(function(plr)
newPlayer(plr)
end)

  1. do you ever save the player’s data to the datastore? if not, then it will return nil
  2. im not sure what the second parameter is in GameDATA:GetAsync(plr.UserId, plr.leaderstats.Stage.Value), i believe this functions accepts 1 param with additional options param but thats not it

Nevermind, I figured out I had to remove plr.leaderstats.Stage.Value from GetAsync

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.