ClickDetector Issue

I’ve just coded this and can’t figure out what the issue is. It prints “a” and “b”, nothing more.

Script:

for _, Object in next, Workspace.Givers.ClickDetector:GetChildren() do
	print("a")
	if Object.Name == "MonkeyMask" then
		print("b")
		Object.ClickDetector.MouseClick:Connect(function(Player)
			print(1)
			local Character = Player.Character
			if Character then
				print(2)
				if not Character:FindFirstChild("MonkeyMask") then
					print(3)
					local NewMask = Object:Clone()
					NewMask.Parent = Character
					NewMask.CFrame = Character.Head.CFrame
					print(4)
					local Weld = Instance.new("WeldConstraint")
					Weld.Part0 = Character.Head
					Weld.Part1 = NewMask
					Weld.Parent = NewMask
					print(5)
				end
			end
		end)
	end
end

Hierarchy:
image

2 Likes

What can I say so far, if you want to print the numbers you should put them into “”. I will research more to help you.

1 Like

If it’s a number, you don’t have to put it into “” for it to print.

Is the script a ServerScript or a LocalScript?

It’s a server script. (------)

I think it does not work because the ClickDetector is in a loop.

No, it should work because he connects a function and functions create a new thread. Think of it as an event listener.

Hey,
try to change the numbers to words!

Again, that isn’t the problem because printing out a number automatically converts it to a string.

Oh sorry,
i forgot print number can not use ""

Any errors? BTW, does the prints work?

Printing out numbers in a string is useless since print automatically converts them as I said.

print("1") -- will work

print(1) -- will also work, think of it like this print(tostring(1))

No, it doesn’t print any errors. The script only prints “a” and “b”.

Where is the script located? charlimit

It’s placed in ServerScriptService.

Just to confirm, the clicking distance is high and you are clicking the part?

Yes, I click the part and it doesn’t detect me clicking.

Can you send me a repro file if possible?

1 Like

Maybe something like that? I’ve recoded some aspects to make it easier and actually find its ClickDetector, seeing everything that has been discussed here.

for _, object in pairs(Workspace.Givers.ClickDetector:GetChildren()) do -- Changed it to pairs instead of next statements
	print("a")
	if object.Name == "MonkeyMask" then
		print("b")
		object.ClickDetector.MouseClick:Connect(function(Player)
			print("c")
			local Character = Player.Character
			if Character ~= nil then
				print("d")
				if Character:FindFirstChild("MonkeyMask") == nil then -- Checks if they already have it
					print("e")
					local NewMask = object:Clone()
					NewMask.Parent = Character
					NewMask.CFrame = Character.Head.CFrame
					print("f")
					local Weld = Instance.new("WeldConstraint")
					Weld.Part0 = Character.Head
					Weld.Part1 = NewMask
					Weld.Parent = NewMask
					print("g")
				end
			end
		end)
	end
end

Here: - - Roblox