Click Detector Tool

Hello! I am currently making this giver so when you click a tool it gives you the tool but I keep getting this error:

image

I was wondering if anyone could explain to me why this isn’t working.

Code:

script.Parent.ClickDetector.MouseClick:Connect(function(player)
	local item = game.ServerStorage["Milk Chocolate Cookie"]:Clone()
	item.Parent = player.Character
end)
end)

Man u have to use cursor functions for a tool i guess no one uses ClickDetector
i hope it fixed ur problem :slight_smile:

Remarks:

  1. You cannot add the clickdetector to the tool. It must be Part or MeshPart.
  2. Your error is caused by the because, script trying to find a property / event in clickdetector called ‘ClickDetector’ (of course clickdetector doesn’t have this property).

You can try the code below by adding your ClickDetector:


local clickdetector = script.Parent.ClickDetector -- Your clickdetector
local item = game.ServerStorage["Milk Chocolate Cookie"] -- Your item to clone

clickdetector.MouseClick:Connect(function(player)
	local Clone = item:Clone()
	local character = player.Character or player.CharacterAdded:Wait() -- Script waiting for player's character to load
	
	if character then
		Clone.Parent = character
	else
		return
	end
end)
1 Like