Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

leader board saving problem?

Asked by 2 years ago

I'm trying to make a game with a leaderboard system where once you touch a part you only get a point once. But whenever you rejoin the game it resets and allows you to get it another time. And because of the datastore that is implemented this allows you to get infinite points. Is the a solution to this?

Here are the scripts in the parts

local level = script.Parent

local function level_complete(otherPart)

view source

01 local player = game.Players:FindFirstChild(otherPart.Parent.Name) 02
03 if player then 04
05 local completed_folder = player.completed 06
07 local alreadyCompleted = completed_folder:FindFirstChild(level.Name) 08
09 if not alreadyCompleted then 10
11 local level_name = Instance.new('StringValue') 12
13 level_name.Name = level.Name 14
15 level_name.Parent = completed_folder 16
17 player.leaderstats.Pogs.Value = player.leaderstats.Pogs.Value + 1 18
19 end 20
21 end

My datastore script

local dataStoreService = game:GetService("DataStoreService") local leaderstatsDataStore = dataStoreService:GetGlobalDataStore("leaderstats")

local loaded = {}

game.Players.PlayerAdded:connect(function(player) local leaderstats = player:WaitForChild("leaderstats") if player.UserId > 0 and player.Parent then local leaderstatsData = leaderstatsDataStore:GetAsync(player.UserId) if leaderstatsData ~= "Request rejected" then if leaderstatsData then for i, stat in ipairs(leaderstats:GetChildren()) do local value = leaderstatsData[stat.Name] if value then stat.Value = value end end end loaded[player] = true end end end)

game.Players.PlayerRemoving:connect(function(player) local leaderstats = player:FindFirstChild("leaderstats") if leaderstats then if loaded[player] then local leaderstatsData = {} for i, stat in ipairs(leaderstats:GetChildren()) do leaderstatsData[stat.Name] = stat.Value end leaderstatsDataStore:SetAsync(player.UserId, leaderstatsData) end end loaded[player] = nil end)

0
Can you just fix the code block??? AProgrammR 398 — 2y
0
Please use a code block. NotThatFamouss 605 — 2y

Answer this question