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:
local Player = game.Players:FindFirstChild(player.Name)
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
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:
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.
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.
Price = 50
script.Parent.ClickDetector.MouseClick:connect(function(player)
local Player = game.Players:FindFirstChild(player.Name)
local leaderstats = Player:FindFirstChild("leaderstats")
local Money = leaderstats:FindFirstChild("Money")
if Money.Value >= 50 then
Money.Value = Money.Value - 50
local Tool = game.Lighting:FindFirstChild("Sword"):Clone()
Tool.Parent = Player.Backpack
end
end)
1 comment
Please accept my answer if I have helped you :)