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()
