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

Gamepass ain't working ?

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

✓ Accepted answer

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 comment

1

Thank you sir, it works! C:

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