I keep on looking at tutorials on YouTube in order to help me learn scripting. However, in many of the tutorials it creates a new leaderstat instead of using a pre-existing one. Here is what I mean by this:
local folder = Instance.new(“Folder”)
cash.Name = “leaderstats”
folder.Parent = plr
All of the tutorials contain this, and I already have a Money leaderstat that I would like to use. I understand that I am able to just remove this but how do I then use the Money leaderstat that I already have?
if you have a pre-existing leaderstat folder inside the player then I would suggest using :WaitForChild(). in this example im using a. Touched event to increase the money of the player
if Hit.Parent:FindFirstChild("Humanoid") then
local Player = game.Players:GetPlayerFromCharacter(Hit.Parent)
local leaderstat = Player:WaitForChild("leaderstats")
leaderstat.Cash.Value = leaderstat.Cash.Value + 10
If you already have a money leaderstat, then you don’t even need the script you posted?? It does the same exact thing, create a leaderstats folder.
Did you mean that you wanted the data to save once the player leaves? If so, you have to use the DataStore service which isn’t the same as leaderstats.
Otherwise, I’m pretty sure you didn’t properly understand what the event connection is doing. The code inside the function runs for each player that joins, and only once for that player. It just creates the folder when they join and does nothing else afterwards.
The reason why it’s inside Players.PlayerAdded:Connect() is because that allows you to easily run it for each player that joins using an event instead of repeatedly checking for new players in a loop.
I already have a save system - the script shown is an example of what is in every script, creating a leaderstat. I am asking help regarding the use of locating the pre-existing one and using it in the script.
Not sure what you’re trying to say, using the line of code below, you can add 5 cash to whatever play you decide from any script. If you want to make leaderstats without scripting, I don’t believe you can. If this isn’t the answer you’re going to have to change how you word this, it makes no sense. Maybe you mean how do you access data from a datastore?