Help fix this problem in obby gear gamepass


I went to buy a gamepass and I got this tool.

But when I rejoin, it disappears from me.

Could you please post the code relating to this.

It’s most likely because you have not specified that it should give the gear to the player if they have purchased it already.

Yes, look.

-- Services

local ServerStorage = game:GetService("ServerStorage")
local MPS = game:GetService("MarketplaceService")
local Players = game:GetService("Players")

-- Variables

local MagicCarpet = ServerStorage:WaitForChild("GamePassItems"):WaitForChild("RainbowMagicCarpet")
local gamepass_id = 18501679
local Button = script.Parent

-- Scripting / Coding

Button.Touched:connect(function(hit)
	local Humanoid = hit.Parent:FindFirstChild("Humanoid")
	if Humanoid then
		local player = Players:GetPlayerFromCharacter(hit.Parent)
		if player then
			MPS:PromptGamePassPurchase(player, 18501679)
		end
	end
end)

MPS.PromptGamePassPurchaseFinished:Connect(function(player, id, purchased)
	if not purchased then
		return
	end
	if id == gamepass_id then
		MagicCarpet:Clone().Parent = player.Backpack
		MagicCarpet:Clone().Parent = player.StarterGear
	end
end)
-- Services

local ServerStorage = game:GetService("ServerStorage")

local MPS = game:GetService("MarketplaceService")

local Players = game:GetService("Players")

--Variables

local MagicCarpet = ServerStorage:WaitForChild("GamePassItems"):WaitForChild("RainbowMagicCarpet")

local gamepass_id = 18501679

--Scripting / Coding

game.Players.PlayerAdded:Connect(function(player)

local OwnsGamepass = MPS:UserOwnsGamePassAsync(player.UserId, gamepass_id)

if OwnsGamepass then MagicCarpet:Clone().Parent = player.Backpack

end

end)

Can’t test it right now since roblox studio is updating but this might be your problem.

You should rather re-parent the clone after cloning it, not in the same statement.

if OwnsGamepass then 
   local copy = MagicCarpet:Clone()
   copy.Parent = player.Backpack
end

Now I will test it in the game

No, it’s not work, same problem

Figured out the problem, it’s trying to parent the tool to the backpack before the backpack is created.

local gamePassItems = ServerStorage:WaitForChild("GamePassItems")
local MagicCarpet = gamePassItems :WaitForChild("RainbowMagicCarpet")

game.Players.PlayerAdded:Connect(function(player)
   player.CharacterAdded:Connect(function()
      local copy = MagicCarpet:clone()
      copy.Parent = game.Players[player.name].Backpack
   end)
end)

Hm, i’m confused for put
Do you change this script?
– Services

local ServerStorage = game:GetService("ServerStorage")

local MPS = game:GetService("MarketplaceService")

local Players = game:GetService("Players")

--Variables

local MagicCarpet = ServerStorage:WaitForChild("GamePassItems"):WaitForChild("RainbowMagicCarpet")

local gamepass_id = 18501679

--Scripting / Coding

game.Players.PlayerAdded:Connect(function(player)

local OwnsGamepass = MPS:UserOwnsGamePassAsync(player.UserId, gamepass_id)

if OwnsGamepass then MagicCarpet:Clone().Parent = player.Backpack

end

end)

Sorry yeah,

game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function()
        local OwnsGamepass = MPS:UserOwnsGamePassAsync(player.UserId, gamepass_id)

        if OwnsGamepass then 
          local copy = MagicCarpet:Clone()
          copy.Parent = player.Backpack
        end
     end)
end)
1 Like

Thank you bro, you very help me : D

1 Like

You are most welcome :slight_smile:

1 Like