I have a datastore which count the deaths but it stopped working. Can someone help?
Asked by
4 years ago Edited 4 years ago
So I have three different leader stats folders in the player service: one for counting a players deaths, time spent in-game and their stage in the lobby but when I run my game it says that all three leader stats folders are not a member of the player. When I look at my player service in my character while in-game, there are three leader stats folders.
Deaths script:
01 | local plrs = game.Players |
02 | local DataStoreService = game:GetService( "DataStoreService" ) |
03 | local DataStore = DataStoreService:GetDataStore( "Deaths" ) |
05 | print ( "Deaths leaderstats working" ) |
07 | plrs.PlayerAdded:Connect( function (plr) |
09 | local jats = Instance.new( "Folder" ) |
10 | jats.Name = "leaderstats" |
13 | local wipeouts = Instance.new( "IntValue" ) |
14 | wipeouts.Name = "Deaths" |
16 | wipeouts.Parent = jats |
17 | local Data = DataStore:GetAsync(plr.UserId) |
21 | game.Players.PlayerRemoving:Connect( function (Player) |
22 | DataStore:SetAsync(Player.UserId, Player.leaderstats.Death.Value) |
26 | plr.CharacterAdded:Connect( function (char) |
28 | local humanoid = char:FindFirstChild( "Humanoid" ) |
30 | humanoid.Died:Connect( function () |
32 | wipeouts.Value = wipeouts.Value + 1 |
Time spent script =
01 | local plrs = game.Players |
02 | local DataStoreService = game:GetService( "DataStoreService" ) |
03 | local DataStore = DataStoreService:GetDataStore( "Seconds" ) |
05 | print ( "Time leaderstats working" ) |
07 | plrs.PlayerAdded:Connect( function (plr) |
09 | local jats = Instance.new( "Folder" ) |
10 | jats.Name = "leaderstats" |
13 | local wipeouts = Instance.new( "IntValue" ) |
14 | wipeouts.Name = "Seconds" |
16 | wipeouts.Parent = jats |
17 | local Data = DataStore:GetAsync(plr.UserId) |
21 | game.Players.PlayerRemoving:Connect( function (Player) |
22 | DataStore:SetAsync(Player.UserId, Player.leaderstats.Seconds.Value) |
26 | plr.CharacterAdded:Connect( function (char) |
29 | wipeouts.Value = wipeouts.Value + 1 |
Stage script:
01 | local dss = game:GetService( "DataStoreService" ) |
02 | local obbyDS = dss:GetDataStore( "ObbyData" ) |
04 | local checkpoints = workspace.Checkpoints |
05 | print ( "Checkpoint leaderstats working" ) |
08 | game.Players.PlayerAdded:Connect( function (plr) |
10 | local obbyData = obbyDS:GetAsync(plr.UserId .. "-obbyStageProgress" ) |
12 | local ls = Instance.new( "Folder" ) |
13 | ls.Name = "leaderstats" |
16 | local stage = Instance.new( "StringValue" ) |
18 | stage.Value = obbyData or 1 |
21 | local char = plr.Character or plr.CharacterAdded:Wait() |
23 | char:WaitForChild( "HumanoidRootPart" ).CFrame = checkpoints [ stage.Value ] .CFrame |
25 | char.Humanoid.Touched:Connect( function (touch) |
27 | if touch.Parent = = checkpoints then |
28 | if ( tonumber (touch.Name) and tonumber (touch.Name) > tonumber (stage.Value)) or touch.Name = = "End" then |
29 | stage.Value = touch.Name |
33 | obbyDS:SetAsync(plr.UserId .. "-obbyStageProgress" , plr.leaderstats.Stage.Value) |
39 | plr.CharacterAdded:Connect( function (char) |
41 | local hrp = char:WaitForChild( "HumanoidRootPart" ) |
42 | local humanoid = char:WaitForChild( "Humanoid" ) |
44 | hrp:GetPropertyChangedSignal( "CFrame" ):Wait() |
46 | hrp.CFrame = checkpoints [ stage.Value ] .CFrame |
48 | humanoid.Touched:Connect( function (touch) |
50 | if touch.Parent = = checkpoints then |
51 | if ( tonumber (touch.Name) and tonumber (touch.Name) > tonumber (stage.Value)) or touch.Name = = "End" then |
52 | stage.Value = touch.Name |
57 | game.Players.PlayerRemoving:Connect( function (player) |
58 | obbyDS:SetAsync(plr.UserId .. "-obbyStageProgress" , plr.leaderstats.Stage.Value) |
This only started happening after I implemented a leaderboard for whoever has played the longest:
01 | local DataStoreService = game:GetService( "DataStoreService" ) |
02 | local WinsLeaderboard = DataStoreService:GetOrderedDataStore( "WinsLeaderBoard" ) |
04 | local function updateLeaderboard() |
05 | local success, errorMessage = pcall ( function () |
06 | local Data = WinsLeaderboard:GetSortedAsync( false , 5 ) |
07 | local WinsPage = Data:GetCurrentPage() |
08 | for Rank, data in ipairs (WinsPage) do |
09 | local userName = game.Players:GetNameFromUserIdAsync( tonumber (data.key)) |
11 | local Seconds = data.value |
12 | local isOnLeaderboard = false |
13 | for i, v in pairs (game.Workspace.Leaderboardarea.Leaderboard.LeaderboardGUI.Holder:GetChildren()) do |
14 | if v.Name 2. Text = = Name then |
15 | isOnLeaderboard = true |
20 | if Seconds and isOnLeaderboard = = false then |
21 | local newLbFrame = game.ReplicatedStorage:WaitForChild( "LeaderboardFrame" ):Clone() |
22 | newLbFrame.Name 2. Text = Name |
23 | newLbFrame.TimeSpent.Text = Seconds |
24 | newLbFrame.Rank.Text = "#" ..Rank |
25 | newLbFrame.Position = UDim 2. new( 0 , 0 , newLbFrame.Position.Y.Scale + (. 08 * #game.Workspace.Leaderboardarea.Leaderboard.LeaderboardGUI.Holder:GetChildren()), 0 ) |
26 | newLbFrame.Parent = game.Workspace.Leaderboardarea.Leaderboard.LeaderboardGUI.Holder |
39 | for _, player in pairs (game.Players:GetPlayers()) do |
40 | WinsLeaderboard:SetAsync(player.UserId, player.leaderstats.Seconds.Value) |
43 | for _, frame in pairs (game.Workspace.Leaderboardarea.Leaderboard.LeaderboardGUI.Holder:GetChildren()) do |