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

How do I make this script charge the player ("cash") from leaderstats?

Asked by 2 years ago
Edited 2 years ago

I want the following script which is attached to a button on a vending machine to charge the player X amount of cash (cash is my in game currency in (leaderstats) and deduct that amount from the player. Any help on this would be greatly appreciated.

function onClicked()
   local Bloxy = game.Lighting.DrinkandFood.DMLEnergy:clone()
   Bloxy.Parent = game.Workspace
   Bloxy.Handle.Position = script.Parent.Parent.HolderD.Position
end

script.Parent.ClickDetector.MouseClick:connect(onClicked) 
0
I appreciate the response. Ive tried a few variations and still cant get it. Looking for someone to show me. shutemupschuetz 0 — 2y

2 answers

Log in to vote
0
Answered by 2 years ago

player is the first parameter of MouseClick so you can use that to get the player. with the player, you can change their leaderstats, etc.

Ad
Log in to vote
0
Answered by 2 years ago
Edited 2 years ago

This code should work:

function onClicked(player)
    local Bloxy = game.Lighting.DrinkandFood.DMLEnergy:Clone()
    Bloxy.Parent = workspace
    Bloxy.Handle.Position = script.Parent.Parent.HolderD.Position

    local cost = 10 -- put your price in the cost variable
    local cash = player.leaderstats.cash 

    if cash.Value >= cost then
        cash.Value = cash.Value - cost
    end

    if cash.Value < cost then
        return end
end

script.Parent.ClickDetector.MouseClick:Connect(onClicked)

If it doesn't work it could be something with the capitalization on stuff like 'cash' it could be a capital 'C'

If this is works for you make it the solution

0
well..looks good. Maybe im missing something though. The end of the (then) statements. Im still getting a error "attempt to compare string <= number " Line 9 onClicked shutemupschuetz 0 — 2y
0
@shutemupschuetz My bad, you see the 'cost' variable. Just replace it without quotation marks. Instead of "10" replace it with 10. I also changed the script too. MarkedTomato 810 — 2y

Answer this question