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
01 | local brick = script.Parent |
02 |
03 | function onTouched(hit) |
04 | for i,player in ipairs (game.Players:GetPlayers()) do |
05 | if player.Character then |
06 | local stat = player:FindFirstChild( "leaderstats" ) |
07 | if stat then |
08 | player.leaderstats.Money.Value = player.leaderstats.Money.Value + 1 |
09 | brick:Destroy() |
10 | end |
11 | end |
12 | end |
13 | end |
14 |
15 |
16 | 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.
01 | game.Players.PlayerAdded:connect( function (player) |
02 | local stats = Instance.new( "IntValue" ) |
03 | stats.Name = "leaderstats" |
04 |
05 | local money = Instance.new( "IntValue" ) |
06 | money.Name = "Money" |
07 |
08 | stats.Parent = player |
09 | money.Parent = stats |
10 | end ) |
This should not be in a brick that will be destroyed but in a script in workspace or ServerScriptService