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

How do you make Game Passes work?

Asked by 8 years ago

Hey guys,

I'm making a tycoon. When they start the game they start with 0 cash. They have the ability to purchase a free house and a free 'sawmill' (which earns them income).

I'm selling a Game Pass for 200 Robux that allows you to start with 500,000 cash. How can I make it so when they enter with a pass, they can start with this amount of cash?

Here's my leader board script:

print("Cash Stuffs running!")


function onPlayerEntered(newPlayer)
    wait(.5)
    local stats = Instance.new("IntValue")
    stats.Name = "leaderstats"
    local stats2 = Instance.new("IntValue")
    stats2.Name = "Tycoon"

    local cash = Instance.new("IntValue")

    cash.Name = "Cash" 
    cash.Value = 0
    cash.Parent = stats
    stats2.Parent = newPlayer   
    stats.Parent = newPlayer
end

game.Players.ChildAdded:connect(onPlayerEntered)

Here's what I'm having trouble trying to implement:

local passId = 382425941 -- change this to your game pass ID.

function isAuthenticated(player) -- checks to see if the player owns your pass
    return game:GetService("MarketplaceService"):PlayerOwnsAsset(player, passId)
end

game.Players.PlayerAdded:connect(function(plr)
    if isAuthenticated(plr) then
        cash.Value = 500,000
    end
end)

Any help would be GREATLY appreciated!

1 answer

Log in to vote
0
Answered by
DevSean 270 Moderation Voter
8 years ago

You had the right code it just needed putting into the leaderboard code. This line is wrong however.

cash.Value = 500,000

This actually sets the value of cash to 500 instead of 500,000, you just want to remove the comma.

print("Cash Stuffs running!")

function onPlayerEntered(newPlayer)
    wait(.5)
    local stats = Instance.new("IntValue")
    stats.Name = "leaderstats"
    local stats2 = Instance.new("IntValue")
    stats2.Name = "Tycoon"

    local cash = Instance.new("IntValue")

    cash.Name = "Cash" 
    cash.Value = 0
    --check if the player owns your gamepass
    if game:GetService("MarketplaceService"):PlayerOwnsAsset(newPlayer, 382425941) then
        cash.Value = 500000 -- change cash to 500,000 (can't have a comma)
    end
    cash.Parent = stats
    stats2.Parent = newPlayer   
    stats.Parent = newPlayer
end

--PlayerAdded instead of ChildAdded
game.Players.PlayerAdded:connect(onPlayerEntered)
Ad

Answer this question