Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

why is this leaderstats script unreliable?

sometimes the deaths leaderboard appears and sometimes it isnt there, why does this happen?

local dss = game:GetService("DataStoreService")

local deathsDataStore = dss:GetDataStore("deathsDataStore")

game.Players.PlayerAdded:Connect(function(player)

    local leaderstats = player:WaitForChild("leaderstats")

    local deaths = Instance.new("IntValue")
    deaths.Name = "Deaths"
    deaths.Parent = leaderstats

    local data
    local success, errormsg = pcall(function()
        data = deathsDataStore:GetAsync(player.UserId.."-deaths")
    end)

    if data == nil then
          data = 0
    end

    if data ~= nil then
        deaths.Value = data
        print(player.Name.."'s deaths data was retrieved!")
    else
        print("Error while getting "..player.Name.."'s deaths data.")
        warn(errormsg)
    end

end)

game.Players.PlayerRemoving:Connect(function(player)

    local success, errormsg = pcall(function()
        deathsDataStore:SetAsync(player.UserId.."-deaths",player.leaderstats.Deaths.Value)
    end)

    if success then
        print(player.Name.."'s deaths data was saved!")
    else
        print("Error when saving "..player.Name.."'s deaths data.")
        warn(errormsg)
    end

end)

3 comments

0

Just wondering, is this the full script?

0

Maybe because the leaderstat's parent isn't specified. The leaderstat's parent should always be the player unless I'm blind and I don't see where it is specified.

0

@VortexGamerPlayerYT yes

1 answer

you have to call the function by usnig WaitForChild

local part = script.Parent.WaitForChild(Connect:function[player])

print("NameOfChild").ReplicatedStorage = Vector3.new("Really red") end)

functionofWaitForChild()

2 comments

0

i dont understand

0

It's actually really easy. you need to locate the function in this case pcall. then you use WaitForChild to attempt to call index

This discussion is preserved as it was. New answers, comments, and votes are closed.