My click part isnt working

  1. My Click detector part isnt working

  2. The part is supposted to give a tool on mouse click, it must do it only once.

  3. I have tried watching Youtube tutorials, doesnt help


-- function to give tool
local function giveTool(player)
	-- check if player already has the tool
	if player.Backpack:FindFirstChild("Crowbar") == nil then
		-- create the tool and add it to the player's backpack
		local Crowbar = Instance.new("Tool")
		Crowbar.Name = "ToolName"
		Crowbar.Parent = player.Backpack
	end
end

-- connect click event to giveTool function
ClickDetector.MouseClick:Connect(function(player)
	giveTool(player)
end)

image
The part is supposted to give you a tool once on click.

1 Like

Try this:


-- function to give tool
local function giveTool(player)
	-- check if player already has the tool
	if not player.Backpack:FindFirstChild("Crowbar") then --I like using "not" since it's easier
		local Crowbar = Instance.new("Tool")
		Crowbar.Name = "Crowbar" --You did not define the name you wanted so you would not get the"Crowbar" item even if the script worked
		Crowbar.Parent = player.Backpack
	end
end

-- connect click event to giveTool function
script.Parent.ClickDetector.MouseClick:Connect(function(player) --You did not define "ClickDetector" so i just replaced it with the location of your actual click detector
	giveTool(player)
end)

I sadly can not test it right now but if it’s working please mark my post as an solution, if it’s not working please tell me the error that you received


the part is working but for some reasson the tool doesnt appear in my hands

btw i changed the crowbar thing to sledgehammer

Oh thats because your creating a new item!

That is because only a tool was created in the Instance code.


-- function to give tool
local function giveTool(player)
	-- check if player already has the tool
	if not player.Backpack:FindFirstChild("SledgeHammer") then --I like using "not" since it's easier
		local SledgeHammer= game.Lighting:FindFirstChild("SledgeHammer"):Clone()
		SledgeHammer.Parent = player.Backpack
	end
end

-- connect click event to giveTool function
script.Parent.ClickDetector.MouseClick:Connect(function(player) --You did not define "ClickDetector" so i just replaced it with the location of your actual click detector
	giveTool(player)
end)
1 Like

This should work, just put your actual sledgehammer tool into lighting and make sure its called “SledgeHammer”

To make tools:

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