I tried this in a script but I couldn't find a leaderboard object so I created one along with the code to add money but then when i tested it it didn't work can someone help
local brick = script.Parent function onTouched(hit) for i,player in ipairs(game.Players:GetPlayers()) do if player.Character then local stat = player:FindFirstChild("leaderstats") if stat then player.leaderstats.Money.Value = player.leaderstats.Money.Value +1 brick:Destroy() end end end end brick.Touched:connect(onTouched)
btw sorry for possible confusion first question
You can't just create a leaderstats object in studio, you need to bind with PlayerAdded
and add a leaderstats value and then a money value under the leaderstats value. I'll provide an example below.
game.Players.PlayerAdded:connect(function(player) local stats = Instance.new("IntValue") stats.Name = "leaderstats" local money = Instance.new("IntValue") money.Name = "Money" stats.Parent = player money.Parent = stats end)
This should not be in a brick that will be destroyed but in a script in workspace or ServerScriptService