Why isnt this script working?

local id = 74373689
local ToolNames = {"Duel Pistols"}
local Storage = game:GetService("ServerStorage")




script.Parent.ClickDetector.MouseClick:Connect(function(p)

	if game.MarketplaceService:UserOwnsGamePassAsync(p.UserId, id) then
		local Backpack = p:WaitForChild("Backpack")
		local mps = game:GetService("MarketplaceService")
		for i = 1, #ToolNames do
			local Tool = Storage:FindFirstChild(ToolNames[i])
			if Tool then
				Tool:clone().Parent = Backpack
				else
				mps:PromptGamePassPurchase(p,id)
			end
		end

	end

end)

this script is supposed to give the player a tool if they own the gamepass when they click the part and if the player does not own the gamepass it prompts a gamepass purchase

You have written it so that the player is only shown the prompt to purchase if they have the game pass but the tool isn’t in Storage.

if your looking for the working script it is here:

local id = 13155292
local ToolNames = {"Duel Pistols"}
local Storage = game:GetService("ServerStorage")




script.Parent.ClickDetector.MouseClick:Connect(function(p)

	if game.MarketplaceService:UserOwnsGamePassAsync(p.UserId, id) then
		local Backpack = p:WaitForChild("Backpack")
		--local mps = game:GetService("MarketplaceService")
		for i = 1, #ToolNames do
			local Tool = Storage:FindFirstChild(ToolNames[i])
			if Tool then
				Tool:clone().Parent = Backpack
				--else
				--mps:PromptGamePassPurchase(p,id)
			end
		end
	else
		local mps = game:GetService("MarketplaceService")
		mps:PromptGamePassPurchase(p,id)
	end
	
	
end)

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