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

One Leaderstat for All Players? (Total Donations)

Um so im trying to make a datastore leaderstats script which creates a value in all players so when ever one players value is changes it is changed for all players. So i have like a gui and i want it to show total donations so im doing it this way, how do i make 1 leadertstat for all players? Heres what i have for the local player but not all players

Sorry for the bad explanation and English im tired lol

local dsService = game:GetService("DataStoreService")
local ds = dsService:GetDataStore("TotalDonations") 

game.Players.PlayerAdded:Connect(function(plr)
    local folder = plr
    local currency = Instance.new("IntValue", folder)
    currency.Name = "TotalDonations"
    currency.Value = ds:GetAsync(plr.UserId) or 0
    currency.Changed:Connect(function()
        ds:SetAsync(plr.UserId, currency.Value)
    end)
end)
 
game.Players.PlayerRemoving:Connect(function(plr)
    ds:SetAsync(plr.UserId, plr.leaderstats.TotalDonations.Value) 
end)

1 answer


local dsService = game:GetService("DataStoreService")
local ds = dsService:GetDataStore("TotalDonationsStats")
 
game.Players.PlayerAdded:Connect(function(plr)
    local folder = Instance.new("Folder", plr)
    folder.Name = "leaderstats"
    local currency = Instance.new("IntValue", folder)
    currency.Name = "TotalDonations" -- Currency name.
    currency.Value = ds:GetAsync(plr.UserId) or 0
    currency.Changed:Connect(function()
        ds:SetAsync(plr.UserId, currency.Value)
    end)
end)
 
game.Players.PlayerRemoving:Connect(function(plr)
    ds:SetAsync(plr.UserId, plr.leaderstats.TotalDonations.Value)
end)

1 comment

0

no not that read the ACTUAL DESCRIPTION, one leaderstats for ALL PLAYERS!

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