Gamepass script not giving sword to the buyer

Hi out there I made a gamepass script that is supposed to give you a sword after purchasing it but it ain’t giving you the sword and I haven’t found an error in the script yet. Can anyone help me with this?


Gamepass Checker Script (This script is located in the ServerScriptService)

local MarketplaceService = game:GetService(“MarketplaceService”)
local ReplicatedStorage = game:GetService(“ReplicatedStorage”)
local Sword = ReplicatedStorage:WaitForChild(“ClasssicSword”)

local gamePassID = 11167961

game.Players.PlayerAdded:Connect(function(player)
wait(1)
local char = game.Workspace:FindFirstChild(player.name)
local hasPass = false

local success , message = pcall(function()
	hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId , gamePassID) 
	
	if hasPass == true then 
		print ("player aldready has the give sword gamepass") 
		Sword.Parent = char
	end
end)  

end)

Gamepass Prompter Script (This script is located in starter player scripts)

local MarketplaceService = game:GetService(“MarketplaceService”)
local ReplicatedStorage = game:GetService(“ReplicatedStorage”)
local Sword = ReplicatedStorage:WaitForChild(“ClasssicSword”)

local gamePassID = 11167961

game.Players.PlayerAdded:Connect(function(player)
wait(1)
local char = game.Workspace:FindFirstChild(player.name)
local hasPass = false

local success , message = pcall(function()
	hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId , gamePassID) 
	
	if hasPass == true then 
		print ("player aldready has the give sword gamepass") 
		Sword.Parent = char
	end
end)  

end)

GamePass Handeler Script (Its located in the ServerScriptService in my Workspace)

local MarketplaceService = game:GetService(“MarketplaceService”)
local gamePassID = 11167961
local ReplicatedStorage = game:GetService(“ReplicatedStorage”)
local Sword = ReplicatedStorage:WaitForChild(“ClasssicSword”)

MarketplaceService.PromptGamePassPurchaseFinished:Connect (function(player , purchasePassID,purchaseSuccess)
if purchaseSuccess == true and purchasePassID == gamePassID then
print (player.name… “purchased the give sword gamepass”)
Sword.Parent = player.Character
end

end)

2 Likes

There are two mistakes in your script

1:

 Sword.Parent = character

It’s not changing it to the player backpack, it’s just changing parents.
You need to do like this:

Sword.Parent = player.Backpack

2:

Sword.Parent = player.Backpack

With this, when the second player joins, the first player sword changes to the second player.
You need to do like this:

 local CloneSword = Sword:Clone()
 CloneSword.Parent = player.Backpack
1 Like

can u pls just tell me in which script should i apply the corrections?

local MarketplaceService = game:GetService("MarketplaceService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Sword = ReplicatedStorage:WaitForChild("ClasssicSword")

local gamePassID = 11167961

game.Players.PlayerAdded:Connect(function(player)
	wait(1)
	local hasPass = false
	
	local success , message = pcall(function()
		hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId , gamePassID) 
		
		if hasPass == true then 
			print ("player aldready has the give sword gamepass") 
			local CloneSword = Sword:Clone()
			CloneSword.Parent = player.Backpack
		end
	end)  
end)
1 Like

You should mark it as a solution so that others who read the post knows that it has been solved or those who want to learn can find it

umm actually its not working

30characters

Have you tested it out yet in game? You must buy the gamepass to test it

umm the dev has the gamepass by the default right

No, you have to buy it. Because the game checks if you have the gamepass or not.

This is incorrect, the game dev owns all game passes by default.

But I had to but the gamepass in order to recieve my items.

The game checks through to see if you have the gamepass

If you created the gamepasses you don’t, like @amadeupworld2 said you own them by default.

Strange, I created my own group gamepasses yet I do not get them. Only those that I bought would be in my inventory

1 Like

Maybe it’s because u spelt already wrong?

well this solution only worked for the prompt gamepass script

I have seen that nobody gave a working solution so far so I decided to help:
Here is modified version of your code (Keep in mind that you typed “Classsic sword” with 3 s in variable so if the tool in replicated storage doesn’t have 3 s you should remove 1)

local MarketplaceService = game:GetService("MarketplaceService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Sword = ReplicatedStorage:WaitForChild("ClasssicSword") -- You wrote Classsic, usually that tool is called Classic so change it if that's the case

local gamePassID = 11167961

game.Players.PlayerAdded:Connect(function(player)
	local char = game.Workspace:FindFirstChild(player.name)
	
	local success , haspass = pcall(function()
		local hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId , gamePassID) 
		return hasPass -- Instead of using variables pcall returns resault 
	end) 
	
	if success and haspass then -- condition is met if request went through and player has pass 
		local Clone = Sword:Clone()
		Clone.Parent = player.StarterGear -- Parented to StarterGear so player gets the tools when respawned 
		local Clone2 = Sword:Clone() 
		repeat wait() until player.Character -- Waits for character before adding tool to inventory
		Clone2.Parent = player.Backpack
	end 
end)

Note: I have tested this and it works perfectly.

2 Likes

Omg thanks a lot it had become a massive hurdle in my scripting progress and now you have fixed it i just don know how should i thank you!! :slight_smile:

1 Like

No problem, if you have any more questions feel free to ask!

2 Likes