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

How to fix leaderstats script problem to account deaths in a Roblox game?

Asked by 3 years ago

I am working for my game, I need help with the leaderstats to track my deaths. There are 2 data values, "Rip's" and "TotalRips" (DataStore), it is working, almost. Although it appears to be working, the problem is the first death doesn't count towards the TotalRips Count, after that it works. I put these 2 scripts in here:

local deathsStore = game:GetService("DataStoreService"):GetDataStore("TotalRips")
function playerAddedHandler(plr)  
    local playerKey = "Player_" .. plr.UserId 
    local leaderstats = Instance.new("Folder", plr)  
    leaderstats.Name = "leaderstats"
    local TotalRips = Instance.new("IntValue", leaderstats)
    TotalRips.Name = "TotalRips"
    TotalRips.Value = deathsStore:GetAsync(playerKey) 
    plr.CharacterAdded:Connect(function(char)
        char.Humanoid.Died:Connect(function()
            plr.leaderstats.TotalRips.Value = plr.leaderstats.TotalRips.Value + 1
            local success, err = pcall(function()
                deathsStore:SetAsync(playerKey, plr.leaderstats.TotalRips.Value)
            end)    
        end)
    end)
end
game.Players.PlayerAdded:Connect(playerAddedHandler)

Also here is another one of the script:

game.Players.PlayerAdded:Connect(function(player)
    local leaderstats
    if player:FindFirstChild("leaderstats") then
        leaderstats = player.leaderstats
    else
        leaderstats = Instance.new("Folder")
        leaderstats.Name = "leaderstats"
        leaderstats.Parent = player
    end
    local Rip = Instance.new("IntValue")
    Rip.Name = "Rip's"
    Rip.Parent = leaderstats

    player.CharacterAdded:Connect(function(char)
        char.Humanoid.Died:Connect(function()

            Rip.Value = Rip.Value + 1


        end)
    end)
end)

I need help because it could be inaccurate for accounting these values.

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

Hello, sorry for that but here is what is usually the problem: 1. You made the variable wrong, here is what it should look like

TotalRips = "TotalRips"
  1. Other things related to TotalRips should also be the children and the parent should be the TotalRips
0
I am sorry but it didn't work, when i paste the code it said: Error: (11,13) Syntax error: Expected identifier when parsing expression, got '['. The Rip's Count is working, put the TotalRips isn't. Roblox200001TA 2 — 3y
Ad

Answer this question