Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How would i make a gamepass that if someone owns it will change a value?

this is what i have so far and it doesnt work

local id = 5546149
 
game.Players.PlayerAdded:Connect(function(player)
    if game:GetService("GamePassService"):PlayerHasPass(player, id) then 
        player.leaderstats1.xpmulti.Value = 0	
        print(player.Name .. " has the game pass!") 
    else
	    player.leaderstats1.xpmulti.Value = 2
        print(player.Name .. " doesn't have the game pass...")
    end
end)

1 answer

✓ Accepted answer

GamePassService only works for old game passes. It is now replaced with MarketplaceService:UserOwnsGamePassAsync() and MarketplaceService:PromptGamePassPurchase() For more information, see this article.

As for your code, this is how it should end up.

local id = 5546149

game.Players.PlayerAdded:Connect(function(player)
    if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, id) then 
        player.leaderstats1.xpmulti.Value = 0   
        print(player.Name .. " has the game pass!") 
    else
        player.leaderstats1.xpmulti.Value = 2
        print(player.Name .. " doesn't have the game pass...")
    end
end)

11 comments

0

the script still doesnt change the value of the leaderstat

0

Does it error? Just reading back over the code, I see it says leaderstats1.xpmulti, which might be a typo on your part.

0

i put leaderstats1 just so it would not appear on the screen

0

Oh okay, got you. Does anything print?

0

the only thing it prints is that i own the gamepass

0

Hmm, how do you know that it's not changing the value? Number value objects have a default value of 0, and you're setting their value to 0 if the player owns the pass...

0

oh yeah i swapped them around and nothing changed

0

Idk man, it's probably something really simple that I'm overlooking.

1

well thanks for trying

1

i found out how to make it work i had to add the value in the script

0

Oh XD of course

This discussion is preserved as it was. New answers, comments, and votes are closed.