Tool Gamepass Script Broken

I made a gamepass tool script but it does not work. It does not even print anything but it’s supposed to if i have the gamepasses, serverside script
(also i have the passes by default)

Script:

wait(1)



game.Players.PlayerAdded:connect(function(Player)
	if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(Player.UserId, 174984875) then 
		print("HasGP")
		local cln = game.ServerStorage:FindFirstChild("Trap Money Bag"):Clone()
		cln.Parent = Player.Backpack
	end
end)



game.Players.PlayerAdded:connect(function(Player)
	if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(Player.UserId, 174985701) then 
		print("HasGP")
		game.ServerStorage.ChildAdded:Connect(function(hit)
			if hit:IsA("Folder") and hit.Name == "Pistols" then
				local descendants = game.ServerStorage:FindFirstChild("Pistols"):GetDescendants()
				for _, descendant in pairs(descendants) do
					if descendant:IsA("Tool") then
						local cln = descendant:Clone()
						cln.Parent = Player.Backpack
						print("Added")
					end
				end
			end
		end)
	end
end)

Judging from this statement, I assume you used a local script to do it. You should be using a server script to handle everything.

image

The problem could also be the wait(1) on the top of the script. Events like the ones written in the script should be connected immediately when a game starts to ensure proper working of it, or else, if a player joins the game at the time the event is not connected, the connected function of the event will not even fire.

i removed it didn’t work asf gsaew6232523 51356

it just printed “hasgp” but didnt do the function

Can you confirm if the script runs by putting a print statement at the top of the script?

Also, this function could return false and you have to confirm it by printing it out.

Which “Hasgp”? There’s two print statements that prints the same thing as it.

Ok it’s working now here is the new script

game.Players.PlayerAdded:connect(function(Player)
	if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(Player.UserId, 174984875) then 
		print("HasGP")
		local cln = game.ServerStorage:WaitForChild("Trap Money Bag"):Clone()
		cln.Parent = Player.Backpack
	else
		print("NoGP")
	end
end)



game.Players.PlayerAdded:connect(function(Player)
	if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(Player.UserId, 174985701) then 
		print("HasGP")
		local descendants = game.ServerStorage:WaitForChild("Pistols"):GetDescendants()
		for _, descendant in pairs(descendants) do
			if descendant:IsA("Tool") then
				local cln = descendant:Clone()
				cln.Parent = Player.Backpack
				print("Added")
			end
		end
	else
		print("NoGP")
	end
end)

Is this solved? Mark this as the solution.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.