Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Click with tool out to weld onto humanoid won't work?

I have a tool with a handle inside, and parts like the helmet for the top to weld. What I want to achieve is when I have the tool out, and clicked. I welds the helmet to my head. The problem is I'm having trouble with the function or mouse click detection, but I got the weld function which is great.

tool = script.Parent
handle = tool:WaitForChild("Handle")

tool.Equipped:Connect(function()
	print("Tool Equipped")
end)

tool.Activated:Connect(function()
	print("Tool Activated")
end)

function Equipped(hit)
	
	tool = script.Parent
	handle = tool:WaitForChild("Handle")

	tool.Equipped:Connect(function()
		print("Tool Equipped")
	end)

	tool.Activated:Connect(function()
		print("Tool Activated")
	end)
	
	if tool.Activated then
		local g = script.Parent.Parent.Top:clone()
		g.Parent = hit.Parent
		local C = g:GetChildren()
		for i=1, #C do
			if C[i].className == "Part" or C[i].className == "UnionOperation" or C[i].className == "MeshPart" then
				local W = Instance.new("Weld")
				W.Part0 = g.Middle
				W.Part1 = C[i]
				local CJ = CFrame.new(g.Middle.Position)
				local C0 = g.Middle.CFrame:inverse()*CJ
				local C1 = C[i].CFrame:inverse()*CJ
				W.C0 = C0
				W.C1 = C1
				W.Parent = g.Middle
			end
			local Y = Instance.new("Weld")
			Y.Part0 = hit.Parent.Head
			Y.Part1 = g.Middle
			Y.C0 = CFrame.new(0, 0, 0)
			Y.Parent = Y.Part0
		end

		local h = g:GetChildren()
		for i = 1, # h do
			h[i].Anchored = false
			h[i].CanCollide = false
		end
		hit.Parent.Saude.Protecao.HelmetProtect.Value = 5000
		hit.Parent.Saude.Protecao.HelmetVida.Value = 3000
	end
end
wait()
g.Destroy()

1 answer

Very easy thing to answer.

You cannot do an if statement to check if the tool is activated, it has to be something like this

tool.Activated:Connect(function()
	-- script here.
end)

Do with this what you will.

This discussion is preserved as it was. New answers, comments, and votes are closed.