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

Gamepass ain't working ?

Asked by
Bulvyte 388 Moderation Voter
7 years ago
tool = game.ReplicatedStorage.Tool

game.Players.PlayerAdded:connect(function(player)
    local allow = game:GetService('BadgeService'):UserHasBadge(player.userId, 289963623)
    if allow then
        local Clone = tool:Clone()
        local Clone2 = tool:Clone()
        local Backpack = player:WaitForChild("Backpack")
        local StarterGear = player:WaitForChild("StarterGear")
        Clone.Parent = Backpack
        Clone2.Parent = StarterGear
    end
end)

If player got the gamepass should give him the tool into the backpack and startergear.

1 answer

Log in to vote
1
Answered by
Discern 1007 Moderation Voter
7 years ago
Edited 7 years ago

The BadgeService is used to award a player a badge or to check if a player has a badge. It does not check if a player has a Game Pass or not.

In order to check if a player has a Game Pass, you use the MarketplaceService. Instead of using UserHasBadge, you would use PlayerOwnsAsset. An alternative way is to use the GamePassService along with PlayerHasPass, although this is not recommended because PlayerHasPass caches the result of the function so the player won't get the tool if they buy the tool in-game.

tool = game.ReplicatedStorage.Tool

game.Players.PlayerAdded:connect(function(player)
    local allow = game:GetService('MarketplaceService'):PlayerOwnsAsset(player, 289963623) --We use the MarketplaceService and PlayerOwnsAsset here instead of BadgeService and UserHasBadge
    if allow then
        local Clone = tool:Clone()
        local Clone2 = tool:Clone()
        local Backpack = player:WaitForChild("Backpack")
        local StarterGear = player:WaitForChild("StarterGear")
        Clone.Parent = Backpack
        Clone2.Parent = StarterGear
    end
end)
1
Thank you sir, it works! C: Bulvyte 388 — 7y
Ad

Answer this question