--solves the problem of tools falling thru houses


local connectedtools = {}

function GetConnection(tool)
	for _,v in pairs(connectedtools) do
		if v == tool then
			return true
		end
	end
	return false
end

game.Players.PlayerAdded:connect(function(plr)
	plr.CharacterAdded:connect(function(char)
		char.ChildAdded:connect(function(child)
			if child:IsA("Tool") and not GetConnection(child) then
				child.Changed:connect(function(property)
					if child and child.Parent ~= nil and property == "Parent" then
						wait(1/30)
						local handle = child:FindFirstChild("Handle")
						if child.Parent == workspace then
							if handle and handle:CanSetNetworkOwnership() and plr then
								handle:SetNetworkOwner(plr)
							end
						else
							if handle and handle:CanSetNetworkOwnership() and plr then
								handle:SetNetworkOwnershipAuto()
							end
						end
					end
				end)
				table.insert(connectedtools,child)
			end
		end)
	end)
end)

while true do --clean table
	wait(1)
	for i,v in pairs(connectedtools) do
		if v.Parent == nil then
			connectedtools[i] = nil
		end
	end
end
