i need help... when i click the buy button the script doesn't work and doesn't take my money or give me the tool
local Remote = Instance.new("RemoteEvent",game:GetService("ReplicatedStorage")) local tools = game.ReplicatedStorage:WaitForChild("Library") Remote.OnServerEvent:Connect(function(player,price,tool) local usercash = player.leaderstats:FindFirstChild("Cash") if usercash.Value >= price then usercash.Value = usercash.Value - price tools[tool]:Clone().Parent = player.Backpack end end)
on line 7 price doesn't have a variable, you can't deduct a set amount from your players money value without a set value. either add a variable for "price" or set the price yourself.
example:
put this at the top:
local price = 10 -- this is how much of your currency it will deduct, change that to whatever
or replace line 7 with:
usercash.Value = usercash.Value - 10 -- again, you can change this to the price you want
I hope this helped!
edit: the item isn't being added to your backpack because the error happens at the line above the tool cloning, so after you fix that error you'll get the item in your backpack too. There's nothing wrong with that line.