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

How do I make a Gamepass that gives the player a custom model tool?

Asked by 6 years ago
local item = game.ServerStorage.SuperExplosivePowerRocketLauncher

game.Players.PlayerAdded:connect(function(plr)
    if game:GetService("MarketplaceService"):PlayerOwnsAsset(plr,4429257) then
local a = item:Clone()
 a.Parent = plr.Backpack
  else
        print(plr.Name .. " doesn't have the game pass...")
    end
end)

I use that code and it says I do not own the Gamepass whenever I test it. Same with when I make the game public and play it (I do not get the SuperExplosivePowerRocketLauncher) I have tried so many scripts but none of them worked. I have tried the PlayerHasPass thing but nothing works. I double checked if the Gamepass was in my possesion, and it was. I need this resolved so I can continue developing my game place.

1 answer

Log in to vote
0
Answered by
Avigant 2374 Moderation Voter Community Moderator
6 years ago

Let's make a few slight modifications. The player's backpack is reset every time they respawn. a is a useless variable name, so we can rename it to something useful. RBXScriptSignal:connect() is deprecated, so we will use RBXScriptSignal:Connect(). We will use the new method to check whether players own gamepasses.

local marketplaceService = game:GetService("MarketplaceService")

local gamePassId = 2838282
local gamePassTool = game.ServerStorage.SuperExplosivePowerRocketLauncher

game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function()
        if not marketplaceService:UserOwnsGamePassAsync(player.UserId, gamePassId) then
            return
        end

        gamePassTool:Clone().Parent = player.Backpack
    end)


end)

Alternatively, we could use player.StarterGear.

Ad

Answer this question