So - I'm working on a remake of Super Check Point, and i need bests that save. Here's what i have so far
local DataStoreService = game:GetService("DataStoreService")
local playerData = DataStoreService:GetDataStore("PlayerData")
local db = 0
local function UpdateStats(plr, stage, mode, dataa, datab)
local data = playerData:GetAsync(plr.UserId)
local best = plr:WaitForChild("Best")
local prbest = plr:WaitForChild("PRBest")
local plrdata = ("Player_" .. plr.UserId)
if mode == "Standard Run" then
if dataa < stage then
best.Value = stage
local success, err = pcall(function()
playerData:SetAsync(plrdata, best.Value)
end)
if not success then
warn('Could not save data!')
end
end
else
if datab < stage then
prbest.Value = stage
local success, err = pcall(function()
playerData:SetAsync(plrdata, prbest.Value)
end)
if not success then
warn('Could not save data!')
end
end
end
end
local function onPlayerJoin(plr) -- Runs when players join
local leaderstats = plr:WaitForChild("leaderstats")
local best = Instance.new("NumberValue")
best.Parent = plr
best.Name = "Best"
local prbest = Instance.new("NumberValue")
prbest.Parent = plr
prbest.Name = "PRBest"
local playerUserId = "Player_" .. plr.UserId
local data = playerData:GetAsync(playerUserId)
print(playerUserId)
if data then
best.Value = data.Best --This is the line returning the error
prbest.Value = data.PRBest
else
best.Value = 1
prbest.Value = 1
end
plr.leaderstats.Stage.Changed:Connect(function()
if db == 0 then
db = 1
UpdateStats(plr,plr.leaderstats.Stage.Value,plr.leaderstats.Mode.Value, best.Value, prbest.Value)
wait(0.2)
db = 0
end
end)
end
game.Players.PlayerAdded:Connect(onPlayerJoin)
but when I run it, it returns the error "Attempt to index number with 'Best'". Can I get some help here? I don't know why its doing this.

5 comments
What line?
Line 46/47
btw, moving my pc, won't be able to respond for a bit
Maybe because it cannot find Best, try adding WaitForChild
Legend, it makes a new value in the player. It needs to MAKE IT before it gets the stuff. and also, this is about the fact it thinks that data = 2