Log in to vote

How to change values of leaderstats in a public script?

Asked by 8 days ago

I am having issues getting access to a players leaderstats folder, I have tried PlayerAdded but that will only run once and I am using while true do loops to update their information, not the best way of doing it and especially not now since I ran into a problem and having to work backwards from my code, I feel like I have to use a localscript but that wont update for other peoples perspectives. If you can direct me in the right direction that would be greatly appreciated <3.

1 answer

Log in to vote
Answered by
sO_Ov 275 Moderation Voter
8 days ago

I don't understand what is exactly your problem, but here's example of how you can access a specific folder and change values inside her

local Players = game:GetService("Players")

--// Handling Joined event and creating folder
   --//Creating Instances
   local Folder ="Folder")
   Folder.Name = 'leaderstats'
   Folder.Parent = plr

   local Value ="NumberValue")
   Value.Name = 'Cash'
   Value.Parent = Folder

--// Adding Cash to players
while wait(5) do
    for i,v in next, Players:GetPlayers() do -- get all players in game
      if v:FindFirstChild("leaderstats") then -- check if the folder already exists
         if v.leaderstats:FindFirstChild("Cash") then -- check if the value already exists
            v.leaderstats.Cash.Value += 10 -- get atual cash amount and increment 10

Answer this question