Gamepass tool gets deleted when player is reset

The title sounds complicated and probably doesn’t make a lot of sense, but it should be a simple fix.
I made a gamepass script where if you own a certain gamepass, it gives you a tool from repstore. the script is in SSS.

However, when you spawn in the first time, you have the tool, but once you reset, the tool dissappears. Here’s a video.

And here’s the script

local MarketplaceService = game:GetService(“MarketplaceService”)
local Players = game:GetService(“Players”)
local repstore = game:GetService(“ReplicatedStorage”)

local gamePassID = 11435761

local function onPlayerAdded(player)

local hasPass = false

local success, message = pcall(function()
hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, gamePassID)
end)

if not success then
warn("Error while checking if player has pass: " … tostring(message))

  return

end

if hasPass == true then
print(player.Name … " owns the game pass with ID " … gamePassID)
local backpack = player:FindFirstChildOfClass(“Backpack”)
if backpack then
repstore[“Huge donator sign.”].Parent = backpack
end

end
end

Players.PlayerAdded:Connect(onPlayerAdded)

Here’s a solution to your problem:

local MarketplaceService = game:GetService(“MarketplaceService”)
local Players = game:GetService(“Players”)
local repstore = game:GetService(“ReplicatedStorage”)

local gamePassID = 11435761

local function onPlayerAdded(player)

	local hasPass = false

	local success, message = pcall(function()
		hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, gamePassID)
	end)

	if not success then
		warn("Error while checking if player has pass: " … tostring(message))
	  	return
	end

	if hasPass == true then
		print(player.Name … " owns the game pass with ID " … gamePassID)
		local backpack = player:FindFirstChildOfClass(“Backpack”)
		if backpack then
			repstore[“Huge donator sign.”].Parent = backpack
		end
	end
	
	player.CharacterAdded:Connect(function()
		if hasPass == true then
			print(player.Name … " owns the game pass with ID " … gamePassID)
			local backpack = player:FindFirstChildOfClass(“Backpack”)
			if backpack then
				repstore[“Huge donator sign.”].Parent = backpack
			end
		end
	end)
end

Players.PlayerAdded:Connect(onPlayerAdded)
1 Like

You only run your script when the player is added. Instead do player.CharacterAdded function so you know when the actual character is loaded.

1 Like

[quote=“BakonBot, post:2, topic:746474”]

> local MarketplaceService = game:GetService(“MarketplaceService”)
> local Players = game:GetService(“Players”)
> local repstore = game:GetService(“ReplicatedStorage”)
> 
> local gamePassID = 11435761
> 
> local function onPlayerAdded(player)
> 
> 	local hasPass = false
> 
> 	local success, message = pcall(function()
> 		hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, gamePassID)
> 	end)
> 
> 	if not success then
> 		warn("Error while checking if player has pass: " … tostring(message))
> 	  	return
> 	end
> 
> 	if hasPass == true then
> 		print(player.Name … " owns the game pass with ID " … gamePassID)
> 		local backpack = player:FindFirstChildOfClass(“Backpack”)
> 		if backpack then
> 			repstore[“Huge donator sign.”].Parent = backpack
> 		end
> 	end
> 	
> 	player.CharacterAdded:Connect(function()
> 		if hasPass == true then
> 			print(player.Name … " owns the game pass with ID " … gamePassID)
> 			local backpack = player:FindFirstChildOfClass(“Backpack”)
> 			if backpack then
> 				repstore[“Huge donator sign.”].Parent = backpack
> 			end
> 		end
> 	end)
> end
> 
> Players.PlayerAdded:Connect(onPlayerAdded)
> ```
> [/quote]
> 
> still doesnt work...
> 
> local MarketplaceService = game:GetService("MarketplaceService")
> local Players = game:GetService("Players")
> local repstore = game:GetService("ReplicatedStorage")
> 
> local gamePassID = 11435761
> 
> local function onPlayerAdded(player)
> 	
> 	local hasPass = false
> 	
> 	local success, message = pcall(function()
> 		hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, gamePassID)
> 	end)
> 	
> 	if not success then
> 	
> 		return
> 	end
> 	
> 	if hasPass == true then
> 		print(player.Name.. " owns the game pass with ID " ..gamePassID)
> 		local backpack = player:FindFirstChildOfClass("Backpack")
> 		if backpack then
> 			repstore["Huge donator sign."].Parent = backpack
> 		end
> 	end
> 	
> 	player.CharacterAdded:Connect(function()
> 		if hasPass == true then
> 			print(player.Name.. " owns the game pass with ID " ..gamePassID)
> 			local backpack = player:FindFirstChildOfClass("Backpack")
> 			if backpack then
> 				repstore["Huge donator sign."].Parent = backpack
> 			end
> 		end
> 	end)
> end
> 
> Players.PlayerAdded:Connect(onPlayerAdded)

still doesnt work

Oh, sorry, I have overlooked some small problems. By the way, whenever giving a player something that you will need to give multiple times, you should :Clone() it first.
Here’s code that should hopefully work:

local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local repstore = game:GetService("ReplicatedStorage")

local gamePassID = 11435761

local function onPlayerAdded(player)

	local hasPass = false

	local success, message = pcall(function()
		hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, gamePassID)
	end)

	if not success then
		warn("Error while checking if player has pass: "..tostring(message))
	  	return
	end
	
	player.CharacterAdded:Connect(function()
		if hasPass == true then
			print(player.Name .." owns the game pass with ID ".. gamePassID)
			local backpack = player:FindFirstChildOfClass("Backpack")
			if backpack then
				repstore["Huge donator sign."]:Clone().Parent = backpack
			end
		end
	end)
end

Players.PlayerAdded:Connect(onPlayerAdded)

Also, you should check the output in Studio whenever something doesn’t work.

yet again, didn’t work, looked in output, nothing popped up…

Make sure in addition to adding the tool to backpack, also add it to StarterGear.

1 Like

nevermind! it works perfectly fine.

oh nevermind it actually doesnt work for some reasonm

i think you can clone it to starter gear also

1 Like

still didnt work…

did you clone it to both startergear and backpack?

is this what its supposed to look like?

local MarketplaceService = game:GetService(“MarketplaceService”)
local Players = game:GetService(“Players”)
local repstore = game:GetService(“ReplicatedStorage”)

local gamePassID = 11435761

local function onPlayerAdded(player)

local hasPass = false

local success, message = pcall(function()
hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, gamePassID)
end)

if not success then
warn("Error while checking if player has pass: "…tostring(message))
return
end

player.CharacterAdded:Connect(function()
if hasPass == true then
print(player.Name …" owns the game pass with ID "… gamePassID)
local backpack = player:FindFirstChildOfClass(“Backpack”)
local startergear = player:FindFirstChildOfClass(“StarterGear”)
if backpack then
local clonedtool = repstore.Donator:Clone()
clonedtool.Parent = backpack
clonedtool.Parent = startergear
end
end
end)
end

Players.PlayerAdded:Connect(onPlayerAdded)

You could use the Character.Humanoid.Died function.

   local MarketplaceService = game:GetService("MarketplaceService")
   local Players = game:GetService("Players")
   local repstore = game:GetService("ReplicatedStorage")

   local gamePassID = 11435761

   local function onPlayerAdded(player)

local hasPass = false

local success, message = pcall(function()
	hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, gamePassID)
end)

if not success then
	warn("Error while checking if player has pass: " .. tostring(message))
	
	return
end

if hasPass == true then
	print(player.Name .. " owns the game pass with ID " .. gamePassID)
	local backpack = player:FindFirstChildOfClass("Backpack")
	local startergear =  player:FindFirstChildOfClass("StarterGear")
	if backpack then
		repstore["Huge donator sign."]:Clone().Parent = backpack--one to backpack
		repstore["Huge donator sign."]:Clone().Parent = startergear--one to startergear
	end
	
end
 end

Players.PlayerAdded:Connect(onPlayerAdded)

still didnt work…

are there any errors in the output?

nope, except for my plugins…

i think i accidently changed the gamepass id copy it again and see if it works

it’s all good now, thank you soo much!!