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

How to make a gamepass that makes the player start with 1500 points?

Asked by 3 years ago

I made a gamepass that gives the player 1500 points when joining but when i test it it stays at 500 points and doesn't give me a error or anything

local MarketplaceService = game:GetService("MarketplaceService")
function onPlayerEntered(newPlayer)
    local stats = Instance.new("IntValue")
    stats.Name = "leaderstats"

    local score = Instance.new("IntValue")

    score.Name = "Points"
    score.Value = 500

    score.Parent = stats    
    stats.Parent = newPlayer
    if MarketplaceService:PlayerOwnsAsset(newPlayer, 15884145) then
        score.Value = 1500
    end
    while true do
        wait(60)
        score.Value = score.Value + 15
    end
end

game.Players.ChildAdded:connect(onPlayerEntered)

2 answers

Log in to vote
0
Answered by
birds3345 177
3 years ago

Try using MarketplaceService:UserOwnsGamePassAsync(playerUserId,gamePassId) instead. Also instead of childAdded use .PlayerAdded

Ad
Log in to vote
0
Answered by 3 years ago

You made a typo with game.Players.ChildAdded:conenct(onPlayerEntered)

It should be game.Players.ChildAdded:Connect(onPlayerEntered)


Also make sure to wrap in pcall() and use UserOwnsGamePassAsync, along with using booleans.

Hello, i haven't tested this code out, but everything should work fine :)

If there's any problems, please @ me and let me know if anything's wrong.

local MarketPlaceService = game:GetService("MarketplaceService")

function onPlayerEntered(newPlayer)

    local stats = Instance.new("IntValue")
    stats.Name = "leaderstats"

    local score = Instance.new("IntValue")

    score.Name = "Points"

    score.Parent = stats
    stats.Parent = newPlayer

    local hasPass = false -- Creating a boolean to use for to check if the player owns the gamepass

    -- Wrapping this in a pcall isn't necessary, but if roblox's servers shutdown or something, then the script won't break.

    local success, errormessage = pcall(function()
        hasPass = MarketPlaceService:UserOwnsGamePassAsync(newPlayer.UserId, 15884145) -- This essentially is setting this boolean to false or true depending on if the player has the gamepass
    end)

    if hasPass then  --|| The player ownes the gamepass

        score.Value = 1500

    else if not hasPass then --|| The player doesn't own the gamepass

            score.Value = 500


        end 

        while wait(60) do

            score.Value += 15 --|| Does the same thing as score.Value = score.Value + 15, you should get used to using this syntax

        end

    end
end

game.Players.PlayerAdded:Connect(onPlayerEntered) --|| Using PlayerAdded is more efficient
0
I made a mistake on else if not hasPass statement, it should be "else". ZOOP1015 44 — 3y
0
:connect is just a deprecated version of :Connect birds3345 177 — 3y
0
:connect still works birds3345 177 — 3y

Answer this question