I have recently been making a game, where I need the money value to rise by one each time the player clicks a part however, it doesn´t work and I can figure it out. Help would be appreciated and I will accept a good answer.
local DataStoreService = game:GetService("DataStoreService")
local MyData = DataStoreService:GetDataStore("MyData")
--Getting Data and Creating leaderboard
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local Money = Instance.new("IntValue")
Money.Name = "Money"
Money.Parent = leaderstats
local Data
local Sucess, ErroMessage = pcall(function()
Data = MyData:GetAsync(player.UserId.."-Money")
end)
if Sucess == true then
Money.Value = Data
else
print("There was an error")
warn(ErroMessage)
end
end)
--Saving Data
game.Players.PlayerRemoving:Connect(function(player)
local Sucess, ErrorMessage = pcall(function()
MyData:SetAsync(player.UserId.."-Money", player.leaderstats.Money.Value)
end)
if Sucess == true then
print("PlayerData sucessfully saved")
else
print("There was an error")
warn(ErrorMessage)
end
end)
local function OnClick()
local TrashFolder = game.Workspace.TrashFolder
local TrashFolderChildren = TrashFolder:GetChildren()
for i, v in pairs(TrashFolderChildren)do
if v.Name == TrashPart then
v.ClickDetector.MouseClick:Connect(function(player)
player.leaderstats.Money.Value = player.leaderstats.Money.Value + 1
end)
end
end
end

2 comments
please accept, as they cant debounce as it goes based off of just a click.
Debounce is not needed!