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.
COMMUNITY QUESTION
How to change values of leaderstats in a public script?
1 answer
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
Players.PlayerAdded:Connect(function(plr)
--//Creating Instances
local Folder = Instance.new("Folder")
Folder.Name = 'leaderstats'
Folder.Parent = plr
local Value = Instance.new("NumberValue")
Value.Name = 'Cash'
Value.Parent = Folder
end)
--// 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
end
end
end
end
This discussion is preserved as it was. New answers, comments, and votes are closed.
