here is the script
a = true b = {} c = {} highest = 0 while a == true do wait (1) for _, player in pairs(game.Players:GetPlayers()) do if player.DataReady == true then PlayerName = player.Name local survived=player:LoadNumber("SurvivedTotal") or 0 table.insert(b,player) table.insert(c,survived) d = 0 for i,v in pairs(c)do d = d+1 wait() if v > highest then highest = v end end script.parent.Text = (b[d]..": "..c[d]) print (c[d]) print (d) d = 0 script.parent.Text = (PlayerName..": "..survived) end d = 0 end b = {} c = {} end
the output is:
(DIR).Script23: Attempt to concentrate field `?` (a userdata value)
Hello,
I have went through your code and made some modifications! Please read the commented code for the rundown of what I've changed and why I've made these changes to your script.
If anything seems wrong, feel free to leave a comment, or change my code yourself!
-- use datastore ds = game:GetService("DataStoreService"):GetGlobalDataStore() a = true -- notice replacing highest with highestPlayer highestPlayer = nil -- turn "b" and "c" into one dictionary table; dic[player] = # survived dic = {} -- decompose repeated / reusable code into functions function updateHighest() -- theres no need for "d" anymore -- however, we don't know if the highest value is old -- need a value to keep track of current ingame highest local current_highest = -1 local current_highestPlayer for player, survived in pairs(dic) do print(player, survived) -- also, no need to wait() here; small list of players to go through if survived > current_highest then current_highestPlayer = player current_highest = survived end end -- highest = highest of current in-game players highestPlayer = current_highestPlayer end function loadUser(player) local survived = ds:GetAsync(player.UserId .. "Survivals") or 0 print(survived) dic[player] = survived end -- use an event that runs a function when something happens to load this users' survivals -- i.e. game.Players.PlayerAdded => new user joins game.Players.PlayerAdded:Connect(loadUser) -- main runtime while a == true do updateHighest() if highestPlayer then -- b[d] is now highestPlayer; c[d] is now dic[highestPlayer] script.Parent.Text = (highestPlayer.Name .. ": " .. dic[highestPlayer]) else print("nobody is here!") end wait(1) end
Please note I did not add a Saving function, because I did not notice one in the original script. I highly encourage you to try making a Saving function using DataStore.