When i click the purchase button it doesnt not work

script.Parent.MouseButton1Click:connect(function()
	local Cost = script.Parent.Parent.Cost.Value
	local Item = script.Parent.Parent.ItemName.Text
	local Player = game.Players.LocalPlayer
	local PurchasedItems = Player:FindFirstChild("PurchasedItems")
	if PurchasedItems then
			local Character = Player.Character
			local StarterGear = Player:FindFirstChild("StarterGear")
			local Backpack = Player:FindFirstChild("Backpack")
			if StarterGear and Backpack then
				print(1)
				local IfEqpedToolAtempt0 = StarterGear:FindFirstChild(Item)
				if IfEqpedToolAtempt0 then
					script.Parent.Parent.Purchase.Text = "Equipped"
					script.Parent.Parent.Purchase.BackgroundColor3 = Color3.fromRGB(255,193,6)
				end
				local IfEqpedTool = Backpack:FindFirstChild(Item)
			    if IfEqpedTool then
				script.Parent.Parent.Purchase.Text = "Equipped!"
				script.Parent.Parent.Purchase.BackgroundColor3 = Color3.fromRGB(255,193,6)
			else
				local IfEqpedToolFindAtempt2 = Character:FindFirstChild(Item)
				if IfEqpedToolFindAtempt2 then
					script.Parent.Parent.Purchase.Text = "Equipped!"
					script.Parent.Parent.Purchase.BackgroundColor3 = Color3.fromRGB(255,193,6)
				else
					local IfToolPurchasedAtempt0 = PurchasedItems:FindFirstChild(Item)
					if IfToolPurchasedAtempt0 then
						script.Parent.Parent.Purchase.Text = "Equipped!"
						script.Parent.Parent.Purchase.BackgroundColor3 = Color3.fromRGB(255,193,6)
						game.ReplicatedStorage.Purchased:FireServer(Item,0)
					else
						print(1)
						if script.Parent.Parent.ItemCost.Text == "Robux" then
							print("This Item Cost Robux!")
						else
						local leaderstats = Player:FindFirstChild("leaderstats")
	if leaderstats then
		local Cash = leaderstats:FindFirstChild("Cash")
		if Cash then
			if Cash.Value >= Cost then
				game.ReplicatedStorage.Purchased:FireServer(Item,Cost)
				script.Parent.Parent.Purchase.Text = "Equipped!"
				script.Parent.Parent.Purchase.BackgroundColor3 = Color3.fromRGB(255,193,6)
				script.Parent.PurchaseSound:Play()
			else
				script.Parent.Parent.Alert.Visible = true
			end
		end
	end	
						end	
					end	
				end
			end
			end
	end
end)

but this one works (script for backpack)

script.Parent.MouseButton1Click:connect(function()
	local Cost = script.Parent.Parent.Cost.Value
	local Item = script.Parent.Parent.ItemName.Text
	local Player = game.Players.LocalPlayer
	local PurchasedItems = Player:FindFirstChild("PurchasedItems")
	if PurchasedItems then
			local Character = Player.Character
			local Finbackpack = Character:FindFirstChild(Item)
			if Finbackpack then
				game.ReplicatedStorage.Purchased:FireServer(Item,0)
				script.Parent.Parent.Purchase.Text = "Equipped!"
				script.Parent.Parent.Purchase.BackgroundColor3 = Color3.fromRGB(255,193,6)
			else
				local FindBackpackInPurchasedItems = PurchasedItems:FindFirstChild(Item)
				if FindBackpackInPurchasedItems then
					game.ReplicatedStorage.Purchased:FireServer(Item,0)
				script.Parent.Parent.Purchase.Text = "Equipped!"
				script.Parent.Parent.Purchase.BackgroundColor3 = Color3.fromRGB(255,193,6)
				else
					if script.Parent.Parent.ItemCost.Text == "Robux" then
							script.Parent.Parent.AlertIfGamepass.Visible = true
						else
					local leaderstats = Player:FindFirstChild("leaderstats")
	if leaderstats then
		local Cash = leaderstats:FindFirstChild("Cash")
		if Cash then
			if Cash.Value >= Cost then
				 game.ReplicatedStorage.Purchased:FireServer(Item,Cost)
				script.Parent.Parent.Purchase.Text = "Equipped!"
				script.Parent.Parent.Purchase.BackgroundColor3 = Color3.fromRGB(255,193,6)
				script.Parent.PurchaseSound:Play() 
			else
				script.Parent.Parent.Alert.Visible = true
			end
		end
	end
	end
				end
			end	
	end
end)

3 comments

0

A little more detail as to where the problem is would help use help you

0

so it is kinda like a mining simulator so basically the purchase button script for the backpacks work perfectly fine but they shovel doesnt, im pretty sure its an error with the script and not an error in placement of gears and stuff

0

i added in the script that does work for the backpack