How to make a hat gamepass?

I’m gonna make a gamepass like if you buy it you will have instantly one hat like a green top hat or i make another gamepass and i got another hat?

Someone can help me?

10 Likes

I suggest checking out this page on the wiki.

2 Likes

ok i will try

2 Likes

There are several ways to do this

  1. Make a “VIP room” and then program the door to let gamepass owners in and then put a button inthere that adds the hat to the avatar when stepped on
  2. Have a gui button that when clicked, checks for ownership of the gamepass, if it isn’t owned it makes an attempt to sell the gamepass, and if it is owned, it equips the hat onto the avatar.

The first one is easiest and capable of being done with free models, although you shouldn’t use them and instead try to figure out how they work and why they work by looking at what apis they are calling and what methods are being used.

The second one is more complex but is more worth learning so that you can do other more fun things with guis :yum:

2 Likes

No, I do not want to make a vip room, I want to make a gamepass that gives you a hat, like the example 2 that you have given of the gui.

2 Likes

Use PromptGamePassPurchaseFinished, and UserOwnsGamePassAsync for new players.

e.g.

local MarketplaceService = game:GetService('MarketplaceService')

local GAMEPASSID = 000000

local function AddHatToCharacter(Character)
	-- Run code to add hat.
    script:FindFirstChildOfClass('Accessory'):Clone().Parent = Character
end

MarketplaceService.PromptGamePassPurchaseFinished:Connect(function(Player, GamePassId, Purchased)
	if Purchased then -- They actually bought it, and didn't click 'Cancel'
		if GamePassId == GAMEPASSID then -- It's the hat gamepass
			Player.CharacterAdded:Connect(function(Character)
				AddHatToCharacter(Character)
			end)
			
			if Player.Character then
				AddHatToCharacter(Player.Character)
			end
		end
	end
end)

game:GetService('Players').PlayerAdded:Connect(function(Player)
	if MarketplaceService:UserOwnsGamePassAsync(Player.UserId, GAMEPASSID) then
		Player.CharacterAdded:Connect(function(Character)
			AddHatToCharacter(Character)
		end)
	end
end)
8 Likes

Yes but in where i put the hat for the players buy the gamepass?

That statement makes no sense to me, but if you are asking how do I make the players get a hat, there are many methods. Can I see an explorer view of your hat?

I said the explorer view, not the hat image.

1 Like

oh sorry

1 Like

i don’t know so much english, but i think you say…

well i don’t know…

1 Like

explorer view you mean the toolbox or the models in the game?

1 Like

No, this kind of stuff. image

that?

1 Like

so i make this game recently and first i wanna know is this

1 Like

You should update your model to an accessory, once it’s an accessory just use the code that I posted earlier (with the Accessory parented to the script, (name of the Accessory does not matter).

Make sure the script is under ServerScriptService.

ok i will try

but the accesory i need to put it in replicatedstorage? or in where?

Please read my post.

wait i’m gonna put a image if what i do is good ok?