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.
You can't set a Value as Object. Instead of using best.Value = data.Best, you have to get the Value of Best, not the object. Use instead:
best.Value = data.Best.Value -- .Value gets the Value of the Object.
This question has been fixed by my self - I had to make a few changes. Too lazy to type them here. maybe later.