I've changed a few variables in my version of your script as 'Player' when you're looking for their leaderstats will confuse things here.
Line 3
Simple, you can't do that! Therefore we will have to find the player another way, the most simplistic way in my opinion is this:
1 | local Player = game.Players:FindFirstChild(player.Name) |
2 | local leaderstats = Player:FindFirstChild( "leaderstats" ) |
You simply get the Player's name from them clicking the brick. Then we search through the game.Players
for that Player who just clicked the brick. As this is a function we can just do a FindFirstChild
, as if it didn't exist it it would not break the rest of the script as it is waiting for nil.
Line 9
1 | local Tool = game.Lightning.Sword:Clone() |
There is no such thing as Lightning
, therefore it is returning an error as it cannot find game.Lightning. You most likely misspelt this, the correct name is: Lighting
.
Line 10
As we located the player through a different way, we can simply just do:
1 | Tool.Parent = Player.Backpack |
The Tool
Just incase the item some how is not added into Lighting, or you misspell the item name in the script then I've added a:FindFirstChild
.
1 | local Tool = game.Lighting:FindFirstChild( "Sword" ):Clone() |
Conclusion
I have, as previously mentioned at the start of my answer, changed a few of your variables as it was a bit confusing to understand, but I've tested it all out in studio and works perfectly. Just make sure you have the 'Sword' in Lighting.
03 | script.Parent.ClickDetector.MouseClick:connect( function (player) |
04 | local Player = game.Players:FindFirstChild(player.Name) |
05 | local leaderstats = Player:FindFirstChild( "leaderstats" ) |
06 | local Money = leaderstats:FindFirstChild( "Money" ) |
07 | if Money.Value > = 50 then |
08 | Money.Value = Money.Value - 50 |
09 | local Tool = game.Lighting:FindFirstChild( "Sword" ):Clone() |
10 | Tool.Parent = Player.Backpack |