This is a decently simple script that completely works in studio. When I actually test it in game, it does't work. Does anyone know why?
01 | script.Parent.Touched:connect( function (part) |
02 | local leaderstats = game.Players.LocalPlayer:WaitForChild( "leaderstats" ) |
03 | local plr = game.Players:GetPlayerFromCharacter(part.Parent) |
04 |
05 | if leaderstats [ "Raw Robloxs" ] .Value ~ = 0 then |
06 | wait( 0.1 ) |
07 | leaderstats.Money.Value = leaderstats.Money.Value + leaderstats [ "Raw Robloxs" ] .Value |
08 | wait( 0.1 ) |
09 | leaderstats [ "Raw Robloxs" ] .Value = 0 |
10 | end |
11 |
12 | end ) |
'LocalPlayer' is for the client only, wich means that the server cannot access it.
A fix would be
01 | script.Parent.Touched:connect( function (part) |
02 | local plr = game.Players:GetPlayerFromCharacter(part.Parent) |
03 |
04 | if plr then |
05 | local leaderstats = plr:WaitForChild( 'leaderstats' ) |
06 | if leaderstats [ "Raw Robloxs" ] .Value ~ = 0 then |
07 | wait( 0.1 ) |
08 | leaderstats.Money.Value = leaderstats.Money.Value + leaderstats [ "Raw Robloxs" ] .Value |
09 | wait( 0.1 ) |
10 | leaderstats [ "Raw Robloxs" ] .Value = 0 |
11 | end |
12 | end |
Btw, your scripts assumes that the 'hit' is a player, never do that, it might be another part, or a random brick.
If you have any more questions (or I made a typo), just ask