Gamepass Tool Sometimes Works

Hello there! I have a game where you can be a Jedi. I have decided to make a gamepass that gives a better tool for the force. However, you won’t get the tool till you rejoin once. It’s happens several times. There isn’t any errors in the output. Help needed!
Script:

local mps = game:GetService("MarketplaceService")
local gamepass_ID = 13469027
local tool = game.ServerStorage["master jedi force"]
	game.Players.PlayerAdded:Connect(function(player)
	local has_pass = mps:UserOwnsGamePassAsync(player.UserId, gamepass_ID)
	player.CharacterAdded:Connect(function()
		if has_pass then
			tool:Clone().Parent = player.Backpack
		end
	end)
end)

Put the tool in StarterGear instead of backpack. This will keep it during respawns.

local mps = game:GetService("MarketplaceService")
local gamepass_ID = 13469027
local tool = game.ServerStorage["master jedi force"]
	game.Players.PlayerAdded:Connect(function(player)
	local has_pass = mps:UserOwnsGamePassAsync(player.UserId, gamepass_ID)
	if has_pass then
        local starterGear = player:WaitForChild("StarterGear")
        tool:Clone().Parent = starterGear
    end
end)

Wouldn’t putting it in startergear give it to all players?

nop

1 Like

No, every player has their own StarterGear container. You can index it with something along the lines of

local Player = path_to_player
local StarterGear = Player:WaitForChild("StarterGear") -- note that waitforchild is only really necessary on the client
1 Like

Doesn’t seem to work, same thing is happening.

Do you mean you’ll only get the tool once or you only get the tool after you purchase the gamepass and rejoin?

If it’s the latter, Redridge’s solution won’t really solve much.

Doesn’t matter how long you’ve owned the gamepass, you gotta rejoin right after joining to get the tool.

Is that what you want (for them to have to rejoin), or is that what you want to fix?

Oh sorry. Then you must make sure to put the tool in the player’s starter gear and backpack if the purchase was successful. You need to add this to the code where you buy the gamepass.

EDIT: The code shown in that case is completely irrelevant as that only runs when the player joins, not when they buy the gamepass.

1 Like

Was just about to reply in regards to this after reading over your code. You accidentally forgot to also clone the tool into the player’s backpack.

local mps = game:GetService("MarketplaceService")
local gamepass_ID = 13469027
local tool = game.ServerStorage["master jedi force"]
	game.Players.PlayerAdded:Connect(function(player)
	local has_pass = mps:UserOwnsGamePassAsync(player.UserId, gamepass_ID)
	if has_pass then
        local starterGear = player:WaitForChild("StarterGear")
        tool:Clone().Parent = starterGear
        tool:Clone().Parent = player.Backpack -- this is what you forgot to add
    end
end)
1 Like

I need a fix for this. (30 more letters)

No need, the character is not yet spawned in that case :stuck_out_tongue:

Thank you! This works fantastically!

1 Like

UserOwnsGamepass yields and can yield to the extent that the character loads before it returns a result.

1 Like

True, you are correct. However, I still don’t understand how it solves the op’s original problem, since that runs only on player joined?

1 Like

The content inside StarterPack gets parented to Backpack every time the character loads. Your code would work if it ran inside a CharacterAdded event.

I understand that. I don’t understand how it solves the problem of giving the tool before rejoining. Since that would need to be given when the gamepass is bought. Anyways, the op seems to have solved their problem so all good!

This is just a tip. You should, keep a value inside of the player for game pass info, like a Bool Value (true or false) which is called like, OwnsJediGamepass, and you can even do some data store trickery with it, so that people cant delete it from their inventory. That makes game passes easier to use. And if you have a data store system, you can gift players gamepasses. And also have gamepasses update right away when you buy them.

local mps = game:GetService("MarketplaceService")
local gamepass_ID = 13469027
local tool = game.ServerStorage["master jedi force"]
game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function()
		if mps:UserOwnsGamePassAsync(player.UserId, gamepass_ID) then
			tool:Clone().Parent = player.Backpack
		end
	end)
end)

This fixes it with the player having to re-join too get the gamepass only now having to
reset their character for the gamepass to load