Click Detector not Working when Moved

I have a vest that the player puts on whenever it is clicked. There is also a part on the vest that, when clicked, makes a mesh visible. The only problem is, the click detector doesn’t work once the vest is placed onto the character.

Here is the script that controls the meshes with the click detector:

local ClickDetector = script.Parent

db = false
 
local function InvAll(obj)
	local shishMeshes = {
		obj.Shish1,
		obj.Shish2,
		obj.Shish3
	}

	for _, shishMesh in ipairs(shishMeshes) do
		if shishMesh then
			shishMesh.Transparency = 1
			wait(0)
		end
	end
end

local Num = 1

ClickDetector.MouseClick:Connect(function(player)
	if not db then
		db = true

		if player.Character and player.Character:FindFirstChild("Humanoid") and player.Character:FindFirstChild("Vest") == nil then
			if Num == 1 then
				script.Parent.Parent.Parent.Shish1.Transparency = 0
				Num = 2
			elseif Num == 2 then
				script.Parent.Parent.Parent.Shish2.Transparency = 0
				script.Parent.Parent.Parent.Shish1.Transparency = 1
				Num = 3
			elseif Num == 3 then
				script.Parent.Parent.Parent.Shish3.Transparency = 0
				script.Parent.Parent.Parent.Shish2.Transparency = 1
				Num = 4
			elseif Num == 4 then
				InvAll(ClickDetector.Parent.Parent)
				Num = 1
			end
		end

		wait(0.1)
		db = false
	end
end)

Here is a video of what is happening when the vest is on the player:

2 Likes

Have you tried printing a statement to see if the clickdetector is working?

It prints when the vest isn’t on the player, but not when it’s on the player.

You might need to connect a touch event to the clone vest. The easiest method is probably to have the click part of the function into a script and put it under the click part.

The script above is a connect touch event inside of the clone vest, and is a child of the click detector inside of the click part.

You check collisions? Humanoidrootpart is bulky.

I just checked, the HumanoidRootPart shouldn’t be interfering with the button. (The HumanoidRootPart is the block around the player)
image

I also tried moving the button inside of the vest away from the player, and it doesn’t even give the click cursor for the ClickDetector. It seems like the ClickDetector isn’t properly moving onto the button when the vest is cloned onto the player

The mouse excludes descendants of the player’s character. As long as the object you are trying to click is a descendant of the character, the mouse will ignore it.

See Mouse | Documentation - Roblox Creator Hub

Note that the Character of the Players.LocalPlayer is ignored by the mouse automatically.

I didn’t know that about players, so I fixed a couple of things, and it now works perfectly. Thanks for the help.

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