Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Not getting item nor is my money getting taken when I click buy?

Asked by 4 years ago

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)

1 answer

Log in to vote
0
Answered by
Osamiku 12
4 years ago
Edited 4 years ago

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.

0
I'm still not getting the tool... No errors or nothing :( FaZeMcKid 0 — 4y
0
Make sure it is a local script Osamiku 12 — 4y
0
it still isn't seeming to work... FaZeMcKid 0 — 4y
Ad

Answer this question