Click detector not working properly

My script will not detect when someone clicks a click detector.

local MarketplaceService = game:GetService("MarketplaceService")

local HeadMod = script.Parent
local CD = HeadMod.Part.ClickDetector
local Item = script.Parent.Item

local Selling = 10658273788

repeat
	wait(1)
until game:IsLoaded()

CD.MouseClick:Connect(function(player)
	local UIToClone = player.PlayerGui.ClothingUI:Clone()
	UIToClone.Parent = player.PlayerGui
	UIToClone.Name = "NewUI"
	UIToClone.Frame.Visible = true

	local Frame = UIToClone.Frame
	local Buy = Frame.Buy
	local Test = Frame.Test
	local Close = Frame.Close
	print("test")

	Frame.Position = UDim2.new(0.5, 0, 2, 0)
	Frame:TweenPosition(UDim2.new(0.5, 0, 0.917, 0))

	Buy.MouseButton1Click:Connect(function()
		MarketplaceService:PromptPurchase(player, Selling)
	end)

	Test.MouseButton1Click:Connect(function()
		local ItemClone = Item:Clone()
		ItemClone.Parent = workspace:FindFirstChild(player.Name)
	end)

	Close.MouseButton1Click:Connect(function()
		Frame:TweenPosition(UDim2.new(0.5, 0, 2, 0))
		wait(1)
		Frame:Destroy()
	end)
end)
1 Like

Is this a local script or a server script? And where is it located?

It’s a server script and it’s in Workspace for now

Try to add some print statements to debug what the issue really is. And I think that three lines you use to wait for the game to load, they are basically useless. The game loads pretty quickly and that three lines might sometimes break the code. I’ve had that issue before.

Alright, thank you so much! I’ll test it now

1 Like

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