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

How to make a button that makes you pay money to spawn a model?

Asked by 5 years ago
Edited 5 years ago

I want to make a game and i want there to be a button to spawn a model and i want the person to pay money for it to spawn like in (Survive Albert) or maybe in (Natural Disaster Survival) where you pay for more disasters and you have to pay a specific amount of Robux. I really don't know how to do it so i would appreciate it if you told me how to do it :].

Edit : i want this part to do the function http://prntscr.com/pdbp4l

0
You should research more about other stuff and learn the basics and then get into the harder stuff like thie for example. Freddan2006YT 88 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

in-game leaderstats:

first you need to insert a numbervalue in the button, after get the player from the character. then check in the leaderstats if the player have equals or greater then the cost. to find that out, you will need to compare the costs. so,

script.Parent.Touched:Connect(function(h)
    local plr = game:GetService("Players"):GetPlayerFromCharacter(h.Parent)
    local currency = plr.leaderstats.PUTCURRENCYNAMEHERE
    local cost = script.Parent.Cost

    if currency.Value >= cost.Value then
        --code here
    end
end)

but, we didn't remove the cash. so that means they can get as many morphs they want so our final product will be:

script.Parent.Touched:Connect(function(h)
    local plr = game:GetService("Players"):GetPlayerFromCharacter(h.Parent)
    local currency = plr.leaderstats.PUTCURRENCYNAMEHERE
    local cost = script.Parent.Cost

    if currency.Value >= cost.Value then
        currency.Value = currency.Value-cost.Value
        --code here
    end
end)

actual robux:

first you need a touched event, a gamepass, and to get the player from the character. then after that, you need a purchase prompt for the gamepass and to get the marketplaceservice. so what would you do is

script.Parent.Touched:Connect(function(h)
    local plr = game:GetService("Players"):GetPlayerFromCharacter(h.Parent)
    marketservice = game:GetService("MarketplaceService")

    if marketservice:UserOwnsGamePassAsync(plr.UserId, gamepassidhere) then
        --code here to spawn morph
    else
        marketservice:PromptGamePassPurchase(plr.UserId,gamepassid)
    end
Ad

Answer this question