I am creating a system that looks at the tool’s name and correlates it to a part in Player.Character
. I intend that when the Tool is equipped, the part attached to the back Torso gets destroyed, but this results in the Tool breaking. It is not being destroyed, but the model detaches.
A Video for Refrence:
Client Script:
char.ChildAdded:Connect(function(tool)
if tool:IsA("Tool") then
local toolmodel = (tool.Name .. "Model")
local partcheck = char:GetChildren()
for index, child in pairs(partcheck) do
if (child:IsA("Part") and child.Name == toolmodel) or (child:FindFirstChildWhichIsA("ObjectValue") and child.Name == "WeldPart") then
print(child, "LS 1")
ToolNameEvent:FireServer(child)
end
if (child:IsA("Part") and child.Name == toolmodel) then
DestroyToolModel.OnClientEvent:Connect(function(destroychild)
if destroychild == true then
print(child, "will be destroyed")
child:Destroy()
destroychild = false
end
end)
end
end
end
end)
Server Script:
plr.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
character.ChildAdded:Connect(function(equipped)
if equipped:IsA("Tool") then
toolEquipped = equipped
ToolNameEvent.OnServerEvent:Connect(function(player, child)
if child:IsA("Part") then
destroychild = true
if destroychild == true then
DestroyToolModel:FireAllClients(destroychild)
destroychild = false
end
end
end)
end
end)