Gamepass not giving me anything for buying it!

Good afternoon!

I was working on a script that gives you a DarkHeart when you buy the gamepass. However, it doesn’t give you anything. How exactly would I fix this?

local MarketPlaceService = game:GetService("MarketplaceService")

local GamepassId = 20246474
local Tool = script.Darkheart 

game.Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Character)
	if MarketPlaceService:UserOwnsGamePassAsync(Player.UserId, GamepassId) then
		local ToolClone = Tool:Clone()
		ToolClone.Parent = Player.Backpack
	end
  end)
end)

Is this in a server or local script and where is the script located.

Server script located in serverscriptservice.

add a print after the if statement to see if its printing > if not you can troubleshoot that line.

Actually I think what your problem really is > is your variables. I think your script is like cloning the variable? if that makes sense. Idk its really weird.

local MarketPlaceService = game:GetService("MarketplaceService")

local GamepassId = 20246474

game.Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Character)
	if MarketPlaceService:UserOwnsGamePassAsync(Player.UserId, GamepassId) then
		local ToolClone = script.Darkheart:Clone()
		ToolClone.Parent = Player.Backpack
	end
  end)
end)

Try this instead

I tried it, bought the gamepass, no DarkHeart.

I mean idk what you’re doing wrong, because I literally just tried the script and it worked for me.

You can take a look at the full file in studio here: GamepassToolScript - Roblox

Make sure the player has loaded in before giving them the tool, I learned this the hard way.

its not on sale though how do we check it?

also this line only runs once, every time the character loads in

if MarketPlaceService:UserOwnsGamePassAsync(Player.UserId, GamepassId) then
		local ToolClone = Tool:Clone()
		ToolClone.Parent = Player.Backpack
end

Updated, should be on sale now.

When I remove your code checking if player owns, it works.

Can you verify that you get the tool when you respawn once you buy it?

Huh!?!?!?! I tried this earlier and nothing worked. Is it because I was in team create? I’m confused.

the reason you do not get the sword is because you do not own the gamepass, if you use a gamepass id you own/created, you should get it, i tried this out, and it worked.

I would buy the gamepass as a test purchase in game, it wouldn’t give me the item.

because your code only runs one time.

try putting a while loop in the character added to check if you bought it, then just buy it as a test purchase.

local MarketPlaceService = game:GetService("MarketplaceService")

local GamepassId = 20286552 -- REPLACE 1234567 WITH YOUR GAMEPASS ID
local Tool = script.Darkheart -- REPLACE GravityCoil WITH THE NAME OF YOUR TOOL

game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		while wait() do
		if MarketPlaceService:UserOwnsGamePassAsync(Player.UserId, GamepassId) then
				local ToolClone = Tool:Clone()
				ToolClone.Parent = Player.Backpack
                break
			end
		end
	end)
end)

Tool:Clone gave me an error, how would I fix this?

what is the error message?

30 ch ars

There wasn’t an error message, but the code still won’t work because of this Tool:Clone.