Having trouble with this

My Scripter that I hired just completely left me in the dark, lol. I was wondering how I can edit this code whereas it doesn’t make a whole new leaderstat, and uses the existing leaderstat “Cash”. Right now, if I’m not mistaken, it just makes a whole new leaderstat and if I implemented that in my game as it is data would corrupt. I think the part of the script I need to edit is the bottom

local hook = "https://discordapp.com/api/webhooks/REDACTED"
local remoteEvent = game.ReplicatedStorage.sendToDiscord
local http = game:GetService("HttpService")
remoteEvent.OnServerEvent:Connect(function(player, player2, amount, reason)
	if (not game.Players:FindFirstChild(player2)) or amount <= 0 then
		return
	end
	print(player)
	print(player2)
	print(amount)
	print(reason)
	game.Players:FindFirstChild(player2).leaderstats.Cash.Value = game.Players:FindFirstChild(player2).leaderstats.Cash.Value - amount
	local date = os.date("!*t")
	local Data = {
		["content"] = player.Name.. " fined " .. player2 .. " $" .. amount .. " because: " .. reason
	}
	Data = http:JSONEncode(Data)
	http:PostAsync(hook, Data)
end)

local function onPlayerJoin(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player
 
	local cash = Instance.new("IntValue")
	cash.Name = "Cash"
	cash.Value = 0
	cash.Parent = leaderstats
end
 
game.Players.PlayerAdded:Connect(onPlayerJoin)

Just a heads up, I’d suggest removing the webhook from line 1 when positing it here, as anyone is able to fire a request to it.

What are you asking exactly? All the “Cash” portion of the code is doing is adding a folder called “leaderstats” to the player and inside that folder an IntValue called “Cash”. Whenever someone joins it will be set to 0 by default. There is really nothing involving “data” other than the initial value of 0. Are you wanting to save the data or something?

Also, i know this is irrelevant to the question being asked but i’d heavily suggest that you remove that remote as it can easily be abused by an exploiter.

a mod removed it, it was an accident. but uhm I already have a leaderstat called Cash, so wouldn’t that break my game if I added another stat called Cash that’s the same thing

If you have two things of the same name that share a parent then yea it could cause issues when it comes to updating the value. There would really be no reason to have two values that hold the players cash, just have your script grab the existing Cash instance and update that rather than creating a duplicate.

-- If you dont want a duplicate created just wait for the other instance and store it.
local leaderstats = Player:WaitForChild("leaderstats")
local Cash = leaderstats:WaitForChild("Cash")

-- Then as an example
Cash.Value = Cash.Value + 100

Assuming that both of your scripts put it into the leaderstats folder you could just remove the onPlayerJoin function and event listener line below that. Then it wouldn’t create a duplicate.

What’s your question? What are you trying to do? This isn’t immediately clear by reading your post but if your intentions are to create another stat value, you can take everything from the creation of cash and just change both the variable and the name of the created IntValue.

local cash = Instance.new("IntValue")
cash.Name = "Cash"
cash.Value = 0
cash.Parent = leaderstats

local kills = Instance.new("IntValue")
kills.Name = "Kills"
kills.Value = 0
kills.Parent = leaderstats

I encourage you to search first or try resolving this problem yourself first before posting threads. There are also several-stat leaderboards you can find in the toolbox. If you are unsure of how to do this, investing time into learning scripting would be worth your time.