Output Players.Player1.PlayerGui.ShopGui.BackGround.items.item4.Script:5: attempt to index local 'Player' (a nil Value)
function Buy(Player) local RS = game:GetService("ReplicatedStorage") local item = RS:WaitForChild("Ball") local Price = 50 local stats = Player.stats if (stats.Cash.Value >= Price) then item:Clone().Parent = Player.Backpack item:Clone().Parent = Player.StarterGear stats.Cash.Value = stats.Cash.Value - Price end end script.Parent.MouseButton1Click:connect(Buy)
I'm guessing you were using leaderstats for this then I don't think it's gonna find something called "stats" inside Player if you used leaderstats then change it to Player.leaderstats
The MouseButton1Click event does not return the player as an argument, this is why you're getting the error. You can use the LocalPlayer property of the Players service to get the current player.
local Player = game.Players.LocalPlayer --Only works in local scripts.
Your final code should look something like this:
local Player = game.Players.LocalPlayer --Gets the current player. local stats = Player:WaitForChild("stats") --In case the stats object is not available, we can wait for it to be available by using WaitForChild. function Buy() local RS = game:GetService("ReplicatedStorage") local item = RS:WaitForChild("Ball") local Price = 50 if (stats.Cash.Value >= Price) then item:Clone().Parent = Player.Backpack item:Clone().Parent = Player.StarterGear stats.Cash.Value = stats.Cash.Value - Price end end script.Parent.MouseButton1Click:connect(Buy)